A lot of annotations a bit everywhere.

This commit is contained in:
themode 2020-10-24 10:46:23 +02:00
parent 3e59c9d396
commit 3d96b7a4b4
63 changed files with 424 additions and 249 deletions

View File

@ -3,6 +3,7 @@ package net.minestom.server;
import net.minestom.server.entity.Player; import net.minestom.server.entity.Player;
import net.minestom.server.network.PacketWriterUtils; import net.minestom.server.network.PacketWriterUtils;
import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacket;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -18,7 +19,7 @@ public interface Viewable {
* @param player the viewer to add * @param player the viewer to add
* @return true if the player has been added, false otherwise (could be because he is already a viewer) * @return true if the player has been added, false otherwise (could be because he is already a viewer)
*/ */
boolean addViewer(Player player); boolean addViewer(@NotNull Player player);
/** /**
* Removes a viewer. * Removes a viewer.
@ -26,13 +27,14 @@ public interface Viewable {
* @param player the viewer to remove * @param player the viewer to remove
* @return true if the player has been removed, false otherwise (could be because he was not a viewer) * @return true if the player has been removed, false otherwise (could be because he was not a viewer)
*/ */
boolean removeViewer(Player player); boolean removeViewer(@NotNull Player player);
/** /**
* Gets all the viewers of this viewable element. * Gets all the viewers of this viewable element.
* *
* @return A Set containing all the element's viewers * @return A Set containing all the element's viewers
*/ */
@NotNull
Set<Player> getViewers(); Set<Player> getViewers();
/** /**
@ -41,7 +43,7 @@ public interface Viewable {
* @param player the player to check * @param player the player to check
* @return true if {@code player} is a viewer, false otherwise * @return true if {@code player} is a viewer, false otherwise
*/ */
default boolean isViewer(Player player) { default boolean isViewer(@NotNull Player player) {
return getViewers().contains(player); return getViewers().contains(player);
} }
@ -53,7 +55,7 @@ public interface Viewable {
* *
* @param packet the packet to send to all viewers * @param packet the packet to send to all viewers
*/ */
default void sendPacketToViewers(ServerPacket packet) { default void sendPacketToViewers(@NotNull ServerPacket packet) {
PacketWriterUtils.writeAndSend(getViewers(), packet); PacketWriterUtils.writeAndSend(getViewers(), packet);
} }
@ -65,7 +67,7 @@ public interface Viewable {
* *
* @param packets the packets to send * @param packets the packets to send
*/ */
default void sendPacketsToViewers(ServerPacket... packets) { default void sendPacketsToViewers(@NotNull ServerPacket... packets) {
for (ServerPacket packet : packets) { for (ServerPacket packet : packets) {
PacketWriterUtils.writeAndSend(getViewers(), packet); PacketWriterUtils.writeAndSend(getViewers(), packet);
} }
@ -78,7 +80,7 @@ public interface Viewable {
* *
* @param packet the packet to send * @param packet the packet to send
*/ */
default void sendPacketToViewersAndSelf(ServerPacket packet) { default void sendPacketToViewersAndSelf(@NotNull ServerPacket packet) {
if (this instanceof Player) { if (this instanceof Player) {
if (getViewers().isEmpty()) { if (getViewers().isEmpty()) {
((Player) this).getPlayerConnection().sendPacket(packet); ((Player) this).getPlayerConnection().sendPacket(packet);
@ -97,7 +99,7 @@ public interface Viewable {
* *
* @param packet the packet to send * @param packet the packet to send
*/ */
private void UNSAFE_sendPacketToViewersAndSelf(ServerPacket packet) { private void UNSAFE_sendPacketToViewersAndSelf(@NotNull ServerPacket packet) {
Set<Player> recipients = new HashSet<>(getViewers()); Set<Player> recipients = new HashSet<>(getViewers());
recipients.add((Player) this); recipients.add((Player) this);
PacketWriterUtils.writeAndSend(recipients, packet); PacketWriterUtils.writeAndSend(recipients, packet);

View File

@ -8,6 +8,7 @@ import net.minestom.server.network.player.PlayerConnection;
import net.minestom.server.utils.PacketUtils; import net.minestom.server.utils.PacketUtils;
import net.minestom.server.utils.advancement.AdvancementUtils; import net.minestom.server.utils.advancement.AdvancementUtils;
import net.minestom.server.utils.validate.Check; import net.minestom.server.utils.validate.Check;
import org.jetbrains.annotations.NotNull;
import java.util.*; import java.util.*;
@ -134,7 +135,7 @@ public class AdvancementTab implements Viewable {
} }
@Override @Override
public synchronized boolean addViewer(Player player) { public synchronized boolean addViewer(@NotNull Player player) {
final boolean result = viewers.add(player); final boolean result = viewers.add(player);
if (!result) { if (!result) {
return false; return false;
@ -151,7 +152,7 @@ public class AdvancementTab implements Viewable {
} }
@Override @Override
public synchronized boolean removeViewer(Player player) { public synchronized boolean removeViewer(@NotNull Player player) {
if (!isViewer(player)) { if (!isViewer(player)) {
return false; return false;
} }
@ -166,6 +167,7 @@ public class AdvancementTab implements Viewable {
return viewers.remove(player); return viewers.remove(player);
} }
@NotNull
@Override @Override
public Set<Player> getViewers() { public Set<Player> getViewers() {
return viewers; return viewers;

View File

@ -6,6 +6,7 @@ import net.minestom.server.entity.Player;
import net.minestom.server.network.packet.server.play.BossBarPacket; import net.minestom.server.network.packet.server.play.BossBarPacket;
import net.minestom.server.utils.MathUtils; import net.minestom.server.utils.MathUtils;
import net.minestom.server.utils.validate.Check; import net.minestom.server.utils.validate.Check;
import org.jetbrains.annotations.NotNull;
import java.util.*; import java.util.*;
import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.CopyOnWriteArraySet;
@ -38,7 +39,7 @@ public class BossBar implements Viewable {
* @param color the boss bar color * @param color the boss bar color
* @param division the boss bar division * @param division the boss bar division
*/ */
public BossBar(ColoredText title, BarColor color, BarDivision division) { public BossBar(ColoredText title, @NotNull BarColor color, @NotNull BarDivision division) {
this.title = title; this.title = title;
this.color = color; this.color = color;
this.division = division; this.division = division;
@ -50,12 +51,12 @@ public class BossBar implements Viewable {
* @param player the player to check the boss bars * @param player the player to check the boss bars
* @return all the visible boss bars of the player, null if not any * @return all the visible boss bars of the player, null if not any
*/ */
public static Set<BossBar> getBossBars(Player player) { public static Set<BossBar> getBossBars(@NotNull Player player) {
return PLAYER_BOSSBAR_MAP.getOrDefault(player, null); return PLAYER_BOSSBAR_MAP.getOrDefault(player, null);
} }
@Override @Override
public synchronized boolean addViewer(Player player) { public synchronized boolean addViewer(@NotNull Player player) {
// Check already viewer // Check already viewer
if (isViewer(player)) { if (isViewer(player)) {
return false; return false;
@ -71,7 +72,7 @@ public class BossBar implements Viewable {
} }
@Override @Override
public synchronized boolean removeViewer(Player player) { public synchronized boolean removeViewer(@NotNull Player player) {
// Check not viewer // Check not viewer
final boolean result = this.viewers.remove(player); final boolean result = this.viewers.remove(player);
if (result) { if (result) {
@ -82,6 +83,7 @@ public class BossBar implements Viewable {
return result; return result;
} }
@NotNull
@Override @Override
public Set<Player> getViewers() { public Set<Player> getViewers() {
return Collections.unmodifiableSet(viewers); return Collections.unmodifiableSet(viewers);
@ -133,6 +135,7 @@ public class BossBar implements Viewable {
* *
* @return the current bossbar color * @return the current bossbar color
*/ */
@NotNull
public BarColor getColor() { public BarColor getColor() {
return color; return color;
} }
@ -142,7 +145,7 @@ public class BossBar implements Viewable {
* *
* @param color the new color of the bossbar * @param color the new color of the bossbar
*/ */
public void setColor(BarColor color) { public void setColor(@NotNull BarColor color) {
this.color = color; this.color = color;
updateStyle(); updateStyle();
} }
@ -152,6 +155,7 @@ public class BossBar implements Viewable {
* *
* @return the current bossbar division * @return the current bossbar division
*/ */
@NotNull
public BarDivision getDivision() { public BarDivision getDivision() {
return division; return division;
} }
@ -161,7 +165,7 @@ public class BossBar implements Viewable {
* *
* @param division the new bossbar division count * @param division the new bossbar division count
*/ */
public void setDivision(BarDivision division) { public void setDivision(@NotNull BarDivision division) {
this.division = division; this.division = division;
updateStyle(); updateStyle();
} }
@ -213,7 +217,7 @@ public class BossBar implements Viewable {
* *
* @param player the player to remove from the map * @param player the player to remove from the map
*/ */
private void removePlayer(Player player) { private void removePlayer(@NotNull Player player) {
if (!PLAYER_BOSSBAR_MAP.containsKey(player)) { if (!PLAYER_BOSSBAR_MAP.containsKey(player)) {
return; return;
} }
@ -231,7 +235,7 @@ public class BossBar implements Viewable {
* *
* @param player the player to create the bossbar to * @param player the player to create the bossbar to
*/ */
private void addToPlayer(Player player) { private void addToPlayer(@NotNull Player player) {
// Add to the map // Add to the map
Set<BossBar> bossBars = PLAYER_BOSSBAR_MAP.computeIfAbsent(player, p -> new HashSet<>()); Set<BossBar> bossBars = PLAYER_BOSSBAR_MAP.computeIfAbsent(player, p -> new HashSet<>());
bossBars.add(this); bossBars.add(this);
@ -252,7 +256,7 @@ public class BossBar implements Viewable {
* *
* @param player the player to remove the bossbar to * @param player the player to remove the bossbar to
*/ */
private void removeToPlayer(Player player) { private void removeToPlayer(@NotNull Player player) {
BossBarPacket bossBarPacket = new BossBarPacket(); BossBarPacket bossBarPacket = new BossBarPacket();
bossBarPacket.uuid = uuid; bossBarPacket.uuid = uuid;
bossBarPacket.action = BossBarPacket.Action.REMOVE; bossBarPacket.action = BossBarPacket.Action.REMOVE;

View File

@ -1,5 +1,8 @@
package net.minestom.server.data; package net.minestom.server.data;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections; import java.util.Collections;
import java.util.Set; import java.util.Set;
@ -12,19 +15,20 @@ public interface Data {
Data EMPTY = new Data() { Data EMPTY = new Data() {
@Override @Override
public <T> void set(String key, T value, Class<T> type) { public <T> void set(@NotNull String key, @NotNull T value, @NotNull Class<T> type) {
} }
@Override @Override
public <T> T get(String key) { public <T> T get(@NotNull String key) {
return null; return null;
} }
@Override @Override
public boolean hasKey(String key) { public boolean hasKey(@NotNull String key) {
return false; return false;
} }
@NotNull
@Override @Override
public Set<String> getKeys() { public Set<String> getKeys() {
return Collections.emptySet(); return Collections.emptySet();
@ -41,7 +45,7 @@ public interface Data {
} }
@Override @Override
public <T> T getOrDefault(String key, T defaultValue) { public <T> T getOrDefault(@NotNull String key, T defaultValue) {
return defaultValue; return defaultValue;
} }
}; };
@ -54,7 +58,7 @@ public interface Data {
* @param type the value type * @param type the value type
* @param <T> the value generic * @param <T> the value generic
*/ */
<T> void set(String key, T value, Class<T> type); <T> void set(@NotNull String key, @NotNull T value, @NotNull Class<T> type);
/** /**
* Retrieves a value based on its key. * Retrieves a value based on its key.
@ -63,7 +67,8 @@ public interface Data {
* @param <T> the value type * @param <T> the value type
* @return the data associated with the key or null * @return the data associated with the key or null
*/ */
<T> T get(String key); @Nullable
<T> T get(@NotNull String key);
/** /**
* Retrieves a value based on its key, give a default value if not found. * Retrieves a value based on its key, give a default value if not found.
@ -73,7 +78,8 @@ public interface Data {
* @param <T> the value type * @param <T> the value type
* @return {@link #get(String)} if found, {@code defaultValue} otherwise * @return {@link #get(String)} if found, {@code defaultValue} otherwise
*/ */
<T> T getOrDefault(String key, T defaultValue); @Nullable
<T> T getOrDefault(@NotNull String key, T defaultValue);
/** /**
* Gets if the data has a key. * Gets if the data has a key.
@ -81,13 +87,14 @@ public interface Data {
* @param key the key to check * @param key the key to check
* @return true if the data contains the key * @return true if the data contains the key
*/ */
boolean hasKey(String key); boolean hasKey(@NotNull String key);
/** /**
* Gets the list of data keys. * Gets the list of data keys.
* *
* @return an unmodifiable {@link Set} containing all the keys * @return an unmodifiable {@link Set} containing all the keys
*/ */
@NotNull
Set<String> getKeys(); Set<String> getKeys();
/** /**

View File

@ -1,5 +1,7 @@
package net.minestom.server.data; package net.minestom.server.data;
import org.jetbrains.annotations.Nullable;
/** /**
* Represents an element which can have a {@link Data} attached to it. * Represents an element which can have a {@link Data} attached to it.
* <p> * <p>
@ -15,6 +17,7 @@ public interface DataContainer {
* *
* @return the {@link Data} of this container, can be null * @return the {@link Data} of this container, can be null
*/ */
@Nullable
Data getData(); Data getData();
/** /**
@ -22,6 +25,6 @@ public interface DataContainer {
* *
* @param data the {@link Data} of this container, null to remove it * @param data the {@link Data} of this container, null to remove it
*/ */
void setData(Data data); void setData(@Nullable Data data);
} }

View File

@ -1,5 +1,7 @@
package net.minestom.server.data; package net.minestom.server.data;
import org.jetbrains.annotations.NotNull;
import java.util.Collections; import java.util.Collections;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -12,25 +14,26 @@ public class DataImpl implements Data {
protected final ConcurrentHashMap<String, Object> data = new ConcurrentHashMap<>(); protected final ConcurrentHashMap<String, Object> data = new ConcurrentHashMap<>();
@Override @Override
public <T> void set(String key, T value, Class<T> type) { public <T> void set(@NotNull String key, @NotNull T value, @NotNull Class<T> type) {
this.data.put(key, value); this.data.put(key, value);
} }
@Override @Override
public <T> T get(String key) { public <T> T get(@NotNull String key) {
return (T) data.get(key); return (T) data.get(key);
} }
@Override @Override
public <T> T getOrDefault(String key, T defaultValue) { public <T> T getOrDefault(@NotNull String key, T defaultValue) {
return (T) data.getOrDefault(key, defaultValue); return (T) data.getOrDefault(key, defaultValue);
} }
@Override @Override
public boolean hasKey(String key) { public boolean hasKey(@NotNull String key) {
return data.containsKey(key); return data.containsKey(key);
} }
@NotNull
@Override @Override
public Set<String> getKeys() { public Set<String> getKeys() {
return Collections.unmodifiableSet(data.keySet()); return Collections.unmodifiableSet(data.keySet());

View File

@ -6,6 +6,7 @@ import it.unimi.dsi.fastutil.shorts.Short2ObjectOpenHashMap;
import net.minestom.server.utils.PrimitiveConversion; import net.minestom.server.utils.PrimitiveConversion;
import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryReader;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -39,7 +40,7 @@ public class SerializableDataImpl extends DataImpl implements SerializableData {
* @throws UnsupportedOperationException if {@code type} is not registered in {@link DataManager} * @throws UnsupportedOperationException if {@code type} is not registered in {@link DataManager}
*/ */
@Override @Override
public <T> void set(String key, T value, Class<T> type) { public <T> void set(@NotNull String key, @NotNull T value, @NotNull Class<T> type) {
if (DATA_MANAGER.getDataType(type) == null) { if (DATA_MANAGER.getDataType(type) == null) {
throw new UnsupportedOperationException("Type " + type.getName() + " hasn't been registered in DataManager#registerType"); throw new UnsupportedOperationException("Type " + type.getName() + " hasn't been registered in DataManager#registerType");
} }

View File

@ -32,6 +32,8 @@ import net.minestom.server.utils.entity.EntityUtils;
import net.minestom.server.utils.player.PlayerUtils; import net.minestom.server.utils.player.PlayerUtils;
import net.minestom.server.utils.time.TimeUnit; import net.minestom.server.utils.time.TimeUnit;
import net.minestom.server.utils.validate.Check; import net.minestom.server.utils.validate.Check;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -124,7 +126,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
private long ticks; private long ticks;
private final EntityTickEvent tickEvent = new EntityTickEvent(this); private final EntityTickEvent tickEvent = new EntityTickEvent(this);
public Entity(EntityType entityType, Position spawnPosition) { public Entity(@NotNull EntityType entityType, @NotNull Position spawnPosition) {
this.id = generateId(); this.id = generateId();
this.entityType = entityType; this.entityType = entityType;
this.uuid = UUID.randomUUID(); this.uuid = UUID.randomUUID();
@ -144,11 +146,11 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
* *
* @param callback the task to execute during the next entity tick * @param callback the task to execute during the next entity tick
*/ */
public void scheduleNextTick(Consumer<Entity> callback) { public void scheduleNextTick(@NotNull Consumer<Entity> callback) {
this.nextTick.add(callback); this.nextTick.add(callback);
} }
public Entity(EntityType entityType) { public Entity(@NotNull EntityType entityType) {
this(entityType, new Position()); this(entityType, new Position());
} }
@ -156,6 +158,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
* @param id the entity unique id ({@link #getEntityId()}) * @param id the entity unique id ({@link #getEntityId()})
* @return the entity having the specified id, null if not found * @return the entity having the specified id, null if not found
*/ */
@Nullable
public static Entity getEntity(int id) { public static Entity getEntity(int id) {
return entityById.getOrDefault(id, null); return entityById.getOrDefault(id, null);
} }
@ -213,9 +216,9 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
* {@link Instance#hasEnabledAutoChunkLoad()} returns true. * {@link Instance#hasEnabledAutoChunkLoad()} returns true.
* *
* @param position the teleport position * @param position the teleport position
* @param callback the callback executed, even if auto chunk is not enabled * @param callback the optional callback executed, even if auto chunk is not enabled
*/ */
public void teleport(Position position, Runnable callback) { public void teleport(@NotNull Position position, @Nullable Runnable callback) {
Check.notNull(position, "Teleport position cannot be null"); Check.notNull(position, "Teleport position cannot be null");
Check.stateCondition(instance == null, "You need to use Entity#setInstance before teleporting an entity!"); Check.stateCondition(instance == null, "You need to use Entity#setInstance before teleporting an entity!");
@ -238,7 +241,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
} }
} }
public void teleport(Position position) { public void teleport(@NotNull Position position) {
teleport(position, null); teleport(position, null);
} }
@ -271,7 +274,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
* *
* @param position the new view * @param position the new view
*/ */
public void setView(Position position) { public void setView(@NotNull Position position) {
setView(position.getYaw(), position.getPitch()); setView(position.getYaw(), position.getPitch());
} }
@ -291,14 +294,17 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
} }
/** /**
* Makes the entity auto viewable or only manually.
*
* @param autoViewable should the entity be automatically viewable for close players * @param autoViewable should the entity be automatically viewable for close players
* @see #isAutoViewable()
*/ */
public void setAutoViewable(boolean autoViewable) { public void setAutoViewable(boolean autoViewable) {
this.autoViewable = autoViewable; this.autoViewable = autoViewable;
} }
@Override @Override
public boolean addViewer(Player player) { public boolean addViewer(@NotNull Player player) {
Check.notNull(player, "Viewer cannot be null"); Check.notNull(player, "Viewer cannot be null");
boolean result = this.viewers.add(player); boolean result = this.viewers.add(player);
if (!result) if (!result)
@ -308,7 +314,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
} }
@Override @Override
public boolean removeViewer(Player player) { public boolean removeViewer(@NotNull Player player) {
Check.notNull(player, "Viewer cannot be null"); Check.notNull(player, "Viewer cannot be null");
if (!viewers.remove(player)) if (!viewers.remove(player))
return false; return false;
@ -320,6 +326,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
return true; return true;
} }
@NotNull
@Override @Override
public Set<Player> getViewers() { public Set<Player> getViewers() {
return Collections.unmodifiableSet(viewers); return Collections.unmodifiableSet(viewers);
@ -331,7 +338,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
} }
@Override @Override
public void setData(Data data) { public void setData(@Nullable Data data) {
this.data = data; this.data = data;
} }
@ -591,6 +598,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
* *
* @return the entity unique id * @return the entity unique id
*/ */
@NotNull
public UUID getUuid() { public UUID getUuid() {
return uuid; return uuid;
} }
@ -600,7 +608,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
* *
* @param uuid the new entity uuid * @param uuid the new entity uuid
*/ */
protected void setUuid(UUID uuid) { protected void setUuid(@NotNull UUID uuid) {
this.uuid = uuid; this.uuid = uuid;
} }
@ -618,6 +626,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
* *
* @return the entity bounding box * @return the entity bounding box
*/ */
@NotNull
public BoundingBox getBoundingBox() { public BoundingBox getBoundingBox() {
return boundingBox; return boundingBox;
} }
@ -640,6 +649,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
* *
* @return the entity chunk * @return the entity chunk
*/ */
@NotNull
public Chunk getChunk() { public Chunk getChunk() {
return instance.getChunkAt(lastX, lastZ); return instance.getChunkAt(lastX, lastZ);
} }
@ -660,7 +670,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
* @throws NullPointerException if {@code instance} is null * @throws NullPointerException if {@code instance} is null
* @throws IllegalStateException if {@code instance} has not been registered in {@link InstanceManager} * @throws IllegalStateException if {@code instance} has not been registered in {@link InstanceManager}
*/ */
public void setInstance(Instance instance) { public void setInstance(@NotNull Instance instance) {
Check.notNull(instance, "instance cannot be null!"); Check.notNull(instance, "instance cannot be null!");
Check.stateCondition(!instance.isRegistered(), Check.stateCondition(!instance.isRegistered(),
"Instances need to be registered, please use InstanceManager#registerInstance or InstanceManager#registerSharedInstance"); "Instances need to be registered, please use InstanceManager#registerInstance or InstanceManager#registerSharedInstance");
@ -682,6 +692,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
* *
* @return the entity current velocity * @return the entity current velocity
*/ */
@NotNull
public Vector getVelocity() { public Vector getVelocity() {
return velocity; return velocity;
} }
@ -693,7 +704,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
* *
* @param velocity the new entity velocity * @param velocity the new entity velocity
*/ */
public void setVelocity(Vector velocity) { public void setVelocity(@NotNull Vector velocity) {
EntityVelocityEvent entityVelocityEvent = new EntityVelocityEvent(this, velocity); EntityVelocityEvent entityVelocityEvent = new EntityVelocityEvent(this, velocity);
callCancellableEvent(EntityVelocityEvent.class, entityVelocityEvent, () -> { callCancellableEvent(EntityVelocityEvent.class, entityVelocityEvent, () -> {
this.velocity.copy(entityVelocityEvent.getVelocity()); this.velocity.copy(entityVelocityEvent.getVelocity());
@ -727,7 +738,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
* @param entity the entity to get the distance from * @param entity the entity to get the distance from
* @return the distance between this and {@code entity} * @return the distance between this and {@code entity}
*/ */
public float getDistance(Entity entity) { public float getDistance(@NotNull Entity entity) {
Check.notNull(entity, "Entity cannot be null"); Check.notNull(entity, "Entity cannot be null");
return getPosition().getDistance(entity.getPosition()); return getPosition().getDistance(entity.getPosition());
} }
@ -737,6 +748,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
* *
* @return the entity vehicle, or null if there is not any * @return the entity vehicle, or null if there is not any
*/ */
@Nullable
public Entity getVehicle() { public Entity getVehicle() {
return vehicle; return vehicle;
} }
@ -748,7 +760,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
* @throws NullPointerException if {@code entity} is null * @throws NullPointerException if {@code entity} is null
* @throws IllegalStateException if {@link #getInstance()} returns null * @throws IllegalStateException if {@link #getInstance()} returns null
*/ */
public void addPassenger(Entity entity) { public void addPassenger(@NotNull Entity entity) {
Check.notNull(entity, "Passenger cannot be null"); Check.notNull(entity, "Passenger cannot be null");
Check.stateCondition(instance == null, "You need to set an instance using Entity#setInstance"); Check.stateCondition(instance == null, "You need to set an instance using Entity#setInstance");
@ -769,7 +781,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
* @throws NullPointerException if {@code entity} is null * @throws NullPointerException if {@code entity} is null
* @throws IllegalStateException if {@link #getInstance()} returns null * @throws IllegalStateException if {@link #getInstance()} returns null
*/ */
public void removePassenger(Entity entity) { public void removePassenger(@NotNull Entity entity) {
Check.notNull(entity, "Passenger cannot be null"); Check.notNull(entity, "Passenger cannot be null");
Check.stateCondition(instance == null, "You need to set an instance using Entity#setInstance"); Check.stateCondition(instance == null, "You need to set an instance using Entity#setInstance");
@ -793,10 +805,12 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
* *
* @return an unmodifiable list containing all the entity passengers * @return an unmodifiable list containing all the entity passengers
*/ */
@NotNull
public Set<Entity> getPassengers() { public Set<Entity> getPassengers() {
return Collections.unmodifiableSet(passengers); return Collections.unmodifiableSet(passengers);
} }
@NotNull
protected SetPassengersPacket getPassengersPacket() { protected SetPassengersPacket getPassengersPacket() {
SetPassengersPacket passengersPacket = new SetPassengersPacket(); SetPassengersPacket passengersPacket = new SetPassengersPacket();
passengersPacket.vehicleEntityId = getEntityId(); passengersPacket.vehicleEntityId = getEntityId();
@ -998,7 +1012,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
* @param position the new position * @param position the new position
* @see #refreshPosition(float, float, float) * @see #refreshPosition(float, float, float)
*/ */
public void refreshPosition(Position position) { public void refreshPosition(@NotNull Position position) {
refreshPosition(position.getX(), position.getY(), position.getZ()); refreshPosition(position.getX(), position.getY(), position.getZ());
} }
@ -1010,7 +1024,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
* @param lastChunk the previous {@link Chunk} of this entity * @param lastChunk the previous {@link Chunk} of this entity
* @param newChunk the new {@link Chunk} of this entity * @param newChunk the new {@link Chunk} of this entity
*/ */
private void updateView(Chunk lastChunk, Chunk newChunk) { private void updateView(@NotNull Chunk lastChunk, @NotNull Chunk newChunk) {
final boolean isPlayer = this instanceof Player; final boolean isPlayer = this instanceof Player;
if (isPlayer) if (isPlayer)
@ -1143,7 +1157,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
* @param position the checked position chunk * @param position the checked position chunk
* @return true if the entity is in the same chunk as {@code position} * @return true if the entity is in the same chunk as {@code position}
*/ */
public boolean sameChunk(Position position) { public boolean sameChunk(@NotNull Position position) {
Check.notNull(position, "Position cannot be null"); Check.notNull(position, "Position cannot be null");
final Position pos = getPosition(); final Position pos = getPosition();
final int chunkX1 = ChunkUtils.getChunkCoordinate((int) Math.floor(pos.getX())); final int chunkX1 = ChunkUtils.getChunkCoordinate((int) Math.floor(pos.getX()));
@ -1161,7 +1175,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
* @param entity the entity to check * @param entity the entity to check
* @return true if both entities are in the same chunk, false otherwise * @return true if both entities are in the same chunk, false otherwise
*/ */
public boolean sameChunk(Entity entity) { public boolean sameChunk(@NotNull Entity entity) {
return sameChunk(entity.getPosition()); return sameChunk(entity.getPosition());
} }
@ -1193,7 +1207,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
* @param delay the time before removing the entity * @param delay the time before removing the entity
* @param timeUnit the unit of the delay * @param timeUnit the unit of the delay
*/ */
public void scheduleRemove(long delay, TimeUnit timeUnit) { public void scheduleRemove(long delay, @NotNull TimeUnit timeUnit) {
delay = timeUnit.toMilliseconds(delay); delay = timeUnit.toMilliseconds(delay);
if (delay == 0) { // Cancel the scheduled remove if (delay == 0) { // Cancel the scheduled remove
@ -1212,6 +1226,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
return scheduledRemoveTime != 0; return scheduledRemoveTime != 0;
} }
@NotNull
protected EntityVelocityPacket getVelocityPacket() { protected EntityVelocityPacket getVelocityPacket() {
final float strength = 8000f / MinecraftServer.TICK_PER_SECOND; final float strength = 8000f / MinecraftServer.TICK_PER_SECOND;
EntityVelocityPacket velocityPacket = new EntityVelocityPacket(); EntityVelocityPacket velocityPacket = new EntityVelocityPacket();
@ -1227,6 +1242,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
* *
* @return The {@link EntityMetaDataPacket} related to this entity * @return The {@link EntityMetaDataPacket} related to this entity
*/ */
@NotNull
public EntityMetaDataPacket getMetadataPacket() { public EntityMetaDataPacket getMetadataPacket() {
EntityMetaDataPacket metaDataPacket = new EntityMetaDataPacket(); EntityMetaDataPacket metaDataPacket = new EntityMetaDataPacket();
metaDataPacket.entityId = getEntityId(); metaDataPacket.entityId = getEntityId();
@ -1239,6 +1255,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
* *
* @return The consumer used to write {@link EntityMetaDataPacket} in {@link #getMetadataPacket()} * @return The consumer used to write {@link EntityMetaDataPacket} in {@link #getMetadataPacket()}
*/ */
@NotNull
public Consumer<BinaryWriter> getMetadataConsumer() { public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> { return packet -> {
fillMetadataIndex(packet, 0); fillMetadataIndex(packet, 0);
@ -1273,7 +1290,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
* @param packet the packet writer * @param packet the packet writer
* @param index the index to fill/write * @param index the index to fill/write
*/ */
protected void fillMetadataIndex(BinaryWriter packet, int index) { protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
switch (index) { switch (index) {
case 0: case 0:
fillStateMetadata(packet); fillStateMetadata(packet);
@ -1299,7 +1316,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
} }
} }
private void fillStateMetadata(BinaryWriter packet) { private void fillStateMetadata(@NotNull BinaryWriter packet) {
packet.writeByte((byte) 0); packet.writeByte((byte) 0);
packet.writeByte(METADATA_BYTE); packet.writeByte(METADATA_BYTE);
byte index0 = 0; byte index0 = 0;
@ -1322,13 +1339,13 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
packet.writeByte(index0); packet.writeByte(index0);
} }
private void fillAirTickMetaData(BinaryWriter packet) { private void fillAirTickMetaData(@NotNull BinaryWriter packet) {
packet.writeByte((byte) 1); packet.writeByte((byte) 1);
packet.writeByte(METADATA_VARINT); packet.writeByte(METADATA_VARINT);
packet.writeVarInt(air); packet.writeVarInt(air);
} }
private void fillCustomNameMetaData(BinaryWriter packet) { private void fillCustomNameMetaData(@NotNull BinaryWriter packet) {
boolean hasCustomName = customName != null; boolean hasCustomName = customName != null;
packet.writeByte((byte) 2); packet.writeByte((byte) 2);
@ -1339,25 +1356,25 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
} }
} }
private void fillCustomNameVisibleMetaData(BinaryWriter packet) { private void fillCustomNameVisibleMetaData(@NotNull BinaryWriter packet) {
packet.writeByte((byte) 3); packet.writeByte((byte) 3);
packet.writeByte(METADATA_BOOLEAN); packet.writeByte(METADATA_BOOLEAN);
packet.writeBoolean(customNameVisible); packet.writeBoolean(customNameVisible);
} }
private void fillSilentMetaData(BinaryWriter packet) { private void fillSilentMetaData(@NotNull BinaryWriter packet) {
packet.writeByte((byte) 4); packet.writeByte((byte) 4);
packet.writeByte(METADATA_BOOLEAN); packet.writeByte(METADATA_BOOLEAN);
packet.writeBoolean(silent); packet.writeBoolean(silent);
} }
private void fillNoGravityMetaData(BinaryWriter packet) { private void fillNoGravityMetaData(@NotNull BinaryWriter packet) {
packet.writeByte((byte) 5); packet.writeByte((byte) 5);
packet.writeByte(METADATA_BOOLEAN); packet.writeByte(METADATA_BOOLEAN);
packet.writeBoolean(noGravity); packet.writeBoolean(noGravity);
} }
private void fillPoseMetaData(BinaryWriter packet) { private void fillPoseMetaData(@NotNull BinaryWriter packet) {
packet.writeByte((byte) 6); packet.writeByte((byte) 6);
packet.writeByte(METADATA_POSE); packet.writeByte(METADATA_POSE);
packet.writeVarInt(pose.ordinal()); packet.writeVarInt(pose.ordinal());

View File

@ -23,6 +23,7 @@ import net.minestom.server.utils.chunk.ChunkUtils;
import net.minestom.server.utils.item.ItemStackUtils; import net.minestom.server.utils.item.ItemStackUtils;
import net.minestom.server.utils.time.TimeUnit; import net.minestom.server.utils.time.TimeUnit;
import net.minestom.server.utils.validate.Check; import net.minestom.server.utils.validate.Check;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -162,7 +163,7 @@ public abstract class EntityCreature extends LivingEntity {
} }
@Override @Override
public boolean addViewer(Player player) { public boolean addViewer(@NotNull Player player) {
final boolean result = super.addViewer(player); final boolean result = super.addViewer(player);
final PlayerConnection playerConnection = player.getPlayerConnection(); final PlayerConnection playerConnection = player.getPlayerConnection();

View File

@ -2,6 +2,7 @@ package net.minestom.server.entity;
import net.minestom.server.network.packet.server.play.SpawnExperienceOrbPacket; import net.minestom.server.network.packet.server.play.SpawnExperienceOrbPacket;
import net.minestom.server.network.player.PlayerConnection; import net.minestom.server.network.player.PlayerConnection;
import org.jetbrains.annotations.NotNull;
public class ExperienceOrb extends Entity { public class ExperienceOrb extends Entity {
@ -25,7 +26,7 @@ public class ExperienceOrb extends Entity {
} }
@Override @Override
public boolean addViewer(Player player) { public boolean addViewer(@NotNull Player player) {
final boolean result = super.addViewer(player); // Add player to viewers list final boolean result = super.addViewer(player); // Add player to viewers list
if (!result) if (!result)
return false; return false;

View File

@ -9,6 +9,8 @@ import net.minestom.server.utils.binary.BinaryWriter;
import net.minestom.server.utils.time.CooldownUtils; import net.minestom.server.utils.time.CooldownUtils;
import net.minestom.server.utils.time.TimeUnit; import net.minestom.server.utils.time.TimeUnit;
import net.minestom.server.utils.time.UpdateOption; import net.minestom.server.utils.time.UpdateOption;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Set; import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -48,6 +50,7 @@ public class ItemEntity extends ObjectEntity {
* *
* @return the merge update option * @return the merge update option
*/ */
@Nullable
public static UpdateOption getMergeUpdateOption() { public static UpdateOption getMergeUpdateOption() {
return mergeUpdateOption; return mergeUpdateOption;
} }
@ -58,7 +61,7 @@ public class ItemEntity extends ObjectEntity {
* *
* @param mergeUpdateOption the new merge update option * @param mergeUpdateOption the new merge update option
*/ */
public static void setMergeUpdateOption(UpdateOption mergeUpdateOption) { public static void setMergeUpdateOption(@Nullable UpdateOption mergeUpdateOption) {
ItemEntity.mergeUpdateOption = mergeUpdateOption; ItemEntity.mergeUpdateOption = mergeUpdateOption;
} }
@ -117,6 +120,7 @@ public class ItemEntity extends ObjectEntity {
this.spawnTime = System.currentTimeMillis(); this.spawnTime = System.currentTimeMillis();
} }
@NotNull
@Override @Override
public Consumer<BinaryWriter> getMetadataConsumer() { public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> { return packet -> {
@ -126,7 +130,7 @@ public class ItemEntity extends ObjectEntity {
} }
@Override @Override
protected void fillMetadataIndex(BinaryWriter packet, int index) { protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
super.fillMetadataIndex(packet, index); super.fillMetadataIndex(packet, index);
if (index == 7) { if (index == 7) {
packet.writeByte((byte) 7); packet.writeByte((byte) 7);
@ -233,7 +237,7 @@ public class ItemEntity extends ObjectEntity {
* @param delay the pickup delay * @param delay the pickup delay
* @param timeUnit the unit of the delay * @param timeUnit the unit of the delay
*/ */
public void setPickupDelay(long delay, TimeUnit timeUnit) { public void setPickupDelay(long delay, @NotNull TimeUnit timeUnit) {
this.pickupDelay = timeUnit.toMilliseconds(delay); this.pickupDelay = timeUnit.toMilliseconds(delay);
} }

View File

@ -21,6 +21,7 @@ import net.minestom.server.utils.Position;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import net.minestom.server.utils.time.TimeUnit; import net.minestom.server.utils.time.TimeUnit;
import net.minestom.server.utils.validate.Check; import net.minestom.server.utils.validate.Check;
import org.jetbrains.annotations.NotNull;
import java.util.Set; import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -122,6 +123,7 @@ public abstract class LivingEntity extends Entity implements EquipmentHandler {
} }
} }
@NotNull
@Override @Override
public Consumer<BinaryWriter> getMetadataConsumer() { public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> { return packet -> {
@ -133,7 +135,7 @@ public abstract class LivingEntity extends Entity implements EquipmentHandler {
} }
@Override @Override
protected void fillMetadataIndex(BinaryWriter packet, int index) { protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
super.fillMetadataIndex(packet, index); super.fillMetadataIndex(packet, index);
if (index == 7) { if (index == 7) {
packet.writeByte((byte) 7); packet.writeByte((byte) 7);

View File

@ -3,6 +3,7 @@ package net.minestom.server.entity;
import net.minestom.server.network.packet.server.play.SpawnEntityPacket; import net.minestom.server.network.packet.server.play.SpawnEntityPacket;
import net.minestom.server.network.player.PlayerConnection; import net.minestom.server.network.player.PlayerConnection;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import org.jetbrains.annotations.NotNull;
public abstract class ObjectEntity extends Entity { public abstract class ObjectEntity extends Entity {
@ -30,7 +31,7 @@ public abstract class ObjectEntity extends Entity {
} }
@Override @Override
public boolean addViewer(Player player) { public boolean addViewer(@NotNull Player player) {
final boolean result = super.addViewer(player); final boolean result = super.addViewer(player);
if (!result) if (!result)
return false; return false;

View File

@ -56,6 +56,8 @@ import net.minestom.server.utils.chunk.ChunkUtils;
import net.minestom.server.utils.validate.Check; import net.minestom.server.utils.validate.Check;
import net.minestom.server.world.DimensionType; import net.minestom.server.world.DimensionType;
import net.minestom.server.world.LevelType; import net.minestom.server.world.LevelType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
@ -542,7 +544,7 @@ public class Player extends LivingEntity implements CommandSender {
} }
@Override @Override
public boolean addViewer(Player player) { public boolean addViewer(@NotNull Player player) {
if (player == this) if (player == this)
return false; return false;
@ -556,7 +558,7 @@ public class Player extends LivingEntity implements CommandSender {
} }
@Override @Override
public boolean removeViewer(Player player) { public boolean removeViewer(@NotNull Player player) {
if (player == this) if (player == this)
return false; return false;
@ -571,7 +573,7 @@ public class Player extends LivingEntity implements CommandSender {
} }
@Override @Override
public void setInstance(Instance instance) { public void setInstance(@NotNull Instance instance) {
Check.notNull(instance, "instance cannot be null!"); Check.notNull(instance, "instance cannot be null!");
Check.argCondition(this.instance == instance, "Instance should be different than the current one"); Check.argCondition(this.instance == instance, "Instance should be different than the current one");
@ -619,6 +621,7 @@ public class Player extends LivingEntity implements CommandSender {
} }
} }
@NotNull
@Override @Override
public Consumer<BinaryWriter> getMetadataConsumer() { public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> { return packet -> {
@ -629,7 +632,7 @@ public class Player extends LivingEntity implements CommandSender {
} }
@Override @Override
protected void fillMetadataIndex(BinaryWriter packet, int index) { protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
super.fillMetadataIndex(packet, index); super.fillMetadataIndex(packet, index);
if (index == 14) { if (index == 14) {
packet.writeByte((byte) 14); packet.writeByte((byte) 14);
@ -643,12 +646,12 @@ public class Player extends LivingEntity implements CommandSender {
} }
/** /**
* Send a plugin message to the player * Sends a plugin message to the player.
* *
* @param channel the message channel * @param channel the message channel
* @param data the message data * @param data the message data
*/ */
public void sendPluginMessage(String channel, byte[] data) { public void sendPluginMessage(@NotNull String channel, @NotNull byte[] data) {
PluginMessagePacket pluginMessagePacket = new PluginMessagePacket(); PluginMessagePacket pluginMessagePacket = new PluginMessagePacket();
pluginMessagePacket.channel = channel; pluginMessagePacket.channel = channel;
pluginMessagePacket.data = data; pluginMessagePacket.data = data;
@ -656,12 +659,12 @@ public class Player extends LivingEntity implements CommandSender {
} }
/** /**
* Send a plugin message to the player * Sends a plugin message to the player.
* *
* @param channel the message channel * @param channel the message channel
* @param message the message * @param message the message
*/ */
public void sendPluginMessage(String channel, String message) { public void sendPluginMessage(@NotNull String channel, @NotNull String message) {
// Write the data // Write the data
BinaryWriter writer = new BinaryWriter(); BinaryWriter writer = new BinaryWriter();
writer.writeSizedString(message); writer.writeSizedString(message);
@ -672,7 +675,7 @@ public class Player extends LivingEntity implements CommandSender {
} }
@Override @Override
public void sendMessage(String message) { public void sendMessage(@NotNull String message) {
sendMessage(ColoredText.of(message)); sendMessage(ColoredText.of(message));
} }
@ -687,7 +690,7 @@ public class Player extends LivingEntity implements CommandSender {
* @param message the message to send, * @param message the message to send,
* you can use {@link ColoredText} and/or {@link RichMessage} to create it easily * you can use {@link ColoredText} and/or {@link RichMessage} to create it easily
*/ */
public void sendMessage(JsonMessage message) { public void sendMessage(@NotNull JsonMessage message) {
sendJsonMessage(message.toString()); sendJsonMessage(message.toString());
} }
@ -697,7 +700,7 @@ public class Player extends LivingEntity implements CommandSender {
* @param text the text with the legacy color formatting * @param text the text with the legacy color formatting
* @param colorChar the color character * @param colorChar the color character
*/ */
public void sendLegacyMessage(String text, char colorChar) { public void sendLegacyMessage(@NotNull String text, char colorChar) {
ColoredText coloredText = ColoredText.ofLegacy(text, colorChar); ColoredText coloredText = ColoredText.ofLegacy(text, colorChar);
sendJsonMessage(coloredText.toString()); sendJsonMessage(coloredText.toString());
} }
@ -707,12 +710,12 @@ public class Player extends LivingEntity implements CommandSender {
* *
* @param text the text with the legacy color formatting * @param text the text with the legacy color formatting
*/ */
public void sendLegacyMessage(String text) { public void sendLegacyMessage(@NotNull String text) {
ColoredText coloredText = ColoredText.ofLegacy(text, ChatParser.COLOR_CHAR); ColoredText coloredText = ColoredText.ofLegacy(text, ChatParser.COLOR_CHAR);
sendJsonMessage(coloredText.toString()); sendJsonMessage(coloredText.toString());
} }
public void sendJsonMessage(String json) { public void sendJsonMessage(@NotNull String json) {
ChatMessagePacket chatMessagePacket = ChatMessagePacket chatMessagePacket =
new ChatMessagePacket(json, ChatMessagePacket.Position.CHAT); new ChatMessagePacket(json, ChatMessagePacket.Position.CHAT);
playerConnection.sendPacket(chatMessagePacket); playerConnection.sendPacket(chatMessagePacket);
@ -723,13 +726,13 @@ public class Player extends LivingEntity implements CommandSender {
* *
* @param message the message that the player will send * @param message the message that the player will send
*/ */
public void chat(String message) { public void chat(@NotNull String message) {
ClientChatMessagePacket chatMessagePacket = new ClientChatMessagePacket(); ClientChatMessagePacket chatMessagePacket = new ClientChatMessagePacket();
chatMessagePacket.message = message; chatMessagePacket.message = message;
addPacketToQueue(chatMessagePacket); addPacketToQueue(chatMessagePacket);
} }
public void playSound(Sound sound, SoundCategory soundCategory, int x, int y, int z, float volume, float pitch) { public void playSound(@NotNull Sound sound, @NotNull SoundCategory soundCategory, int x, int y, int z, float volume, float pitch) {
SoundEffectPacket soundEffectPacket = new SoundEffectPacket(); SoundEffectPacket soundEffectPacket = new SoundEffectPacket();
soundEffectPacket.soundId = sound.getId(); soundEffectPacket.soundId = sound.getId();
soundEffectPacket.soundCategory = soundCategory; soundEffectPacket.soundCategory = soundCategory;
@ -751,7 +754,7 @@ public class Player extends LivingEntity implements CommandSender {
* @param data data for the effect * @param data data for the effect
* @param disableRelativeVolume disable volume scaling based on distance * @param disableRelativeVolume disable volume scaling based on distance
*/ */
public void playEffect(Effects effect, int x, int y, int z, int data, boolean disableRelativeVolume) { public void playEffect(@NotNull Effects effect, int x, int y, int z, int data, boolean disableRelativeVolume) {
EffectPacket packet = new EffectPacket(); EffectPacket packet = new EffectPacket();
packet.effectId = effect.getId(); packet.effectId = effect.getId();
packet.position = new BlockPosition(x, y, z); packet.position = new BlockPosition(x, y, z);
@ -775,7 +778,7 @@ public class Player extends LivingEntity implements CommandSender {
* @param header the header text * @param header the header text
* @param footer the footer text * @param footer the footer text
*/ */
public void sendHeaderFooter(ColoredText header, ColoredText footer) { public void sendHeaderFooter(@NotNull ColoredText header, @NotNull ColoredText footer) {
PlayerListHeaderAndFooterPacket playerListHeaderAndFooterPacket = new PlayerListHeaderAndFooterPacket(); PlayerListHeaderAndFooterPacket playerListHeaderAndFooterPacket = new PlayerListHeaderAndFooterPacket();
playerListHeaderAndFooterPacket.emptyHeader = header == null; playerListHeaderAndFooterPacket.emptyHeader = header == null;
playerListHeaderAndFooterPacket.emptyFooter = footer == null; playerListHeaderAndFooterPacket.emptyFooter = footer == null;
@ -792,7 +795,7 @@ public class Player extends LivingEntity implements CommandSender {
* @param action the action of the title (where to show it) * @param action the action of the title (where to show it)
* @see #sendTitleTime(int, int, int) to specify the display time * @see #sendTitleTime(int, int, int) to specify the display time
*/ */
private void sendTitle(ColoredText text, TitlePacket.Action action) { private void sendTitle(@NotNull ColoredText text, @NotNull TitlePacket.Action action) {
TitlePacket titlePacket = new TitlePacket(); TitlePacket titlePacket = new TitlePacket();
titlePacket.action = action; titlePacket.action = action;
@ -820,7 +823,7 @@ public class Player extends LivingEntity implements CommandSender {
* @param subtitle the subtitle message * @param subtitle the subtitle message
* @see #sendTitleTime(int, int, int) to specify the display time * @see #sendTitleTime(int, int, int) to specify the display time
*/ */
public void sendTitleSubtitleMessage(ColoredText title, ColoredText subtitle) { public void sendTitleSubtitleMessage(@NotNull ColoredText title, @NotNull ColoredText subtitle) {
sendTitle(title, TitlePacket.Action.SET_TITLE); sendTitle(title, TitlePacket.Action.SET_TITLE);
sendTitle(subtitle, TitlePacket.Action.SET_SUBTITLE); sendTitle(subtitle, TitlePacket.Action.SET_SUBTITLE);
} }
@ -831,7 +834,7 @@ public class Player extends LivingEntity implements CommandSender {
* @param title the title message * @param title the title message
* @see #sendTitleTime(int, int, int) to specify the display time * @see #sendTitleTime(int, int, int) to specify the display time
*/ */
public void sendTitleMessage(ColoredText title) { public void sendTitleMessage(@NotNull ColoredText title) {
sendTitle(title, TitlePacket.Action.SET_TITLE); sendTitle(title, TitlePacket.Action.SET_TITLE);
} }
@ -841,7 +844,7 @@ public class Player extends LivingEntity implements CommandSender {
* @param subtitle the subtitle message * @param subtitle the subtitle message
* @see #sendTitleTime(int, int, int) to specify the display time * @see #sendTitleTime(int, int, int) to specify the display time
*/ */
public void sendSubtitleMessage(ColoredText subtitle) { public void sendSubtitleMessage(@NotNull ColoredText subtitle) {
sendTitle(subtitle, TitlePacket.Action.SET_SUBTITLE); sendTitle(subtitle, TitlePacket.Action.SET_SUBTITLE);
} }
@ -851,7 +854,7 @@ public class Player extends LivingEntity implements CommandSender {
* @param actionBar the action bar message * @param actionBar the action bar message
* @see #sendTitleTime(int, int, int) to specify the display time * @see #sendTitleTime(int, int, int) to specify the display time
*/ */
public void sendActionBarMessage(ColoredText actionBar) { public void sendActionBarMessage(@NotNull ColoredText actionBar) {
sendTitle(actionBar, TitlePacket.Action.SET_ACTION_BAR); sendTitle(actionBar, TitlePacket.Action.SET_ACTION_BAR);
} }
@ -890,7 +893,7 @@ public class Player extends LivingEntity implements CommandSender {
} }
@Override @Override
public boolean isImmune(DamageType type) { public boolean isImmune(@NotNull DamageType type) {
if (!getGameMode().canTakeDamage()) { if (!getGameMode().canTakeDamage()) {
return type != DamageType.VOID; return type != DamageType.VOID;
} }
@ -898,7 +901,7 @@ public class Player extends LivingEntity implements CommandSender {
} }
@Override @Override
public void setAttribute(Attribute attribute, float value) { public void setAttribute(@NotNull Attribute attribute, float value) {
super.setAttribute(attribute, value); super.setAttribute(attribute, value);
if (playerConnection != null) if (playerConnection != null)
playerConnection.sendPacket(getPropertiesPacket()); playerConnection.sendPacket(getPropertiesPacket());
@ -1022,6 +1025,7 @@ public class Player extends LivingEntity implements CommandSender {
* @return the player skin object, * @return the player skin object,
* null means that the player has his {@link #getUuid()} default skin * null means that the player has his {@link #getUuid()} default skin
*/ */
@Nullable
public PlayerSkin getSkin() { public PlayerSkin getSkin() {
return skin; return skin;
} }
@ -1034,7 +1038,7 @@ public class Player extends LivingEntity implements CommandSender {
* @param skin the player skin, null to reset it to his {@link #getUuid()} default skin * @param skin the player skin, null to reset it to his {@link #getUuid()} default skin
* @see PlayerSkinInitEvent if you want to apply the skin at connection * @see PlayerSkinInitEvent if you want to apply the skin at connection
*/ */
public synchronized void setSkin(PlayerSkin skin) { public synchronized void setSkin(@Nullable PlayerSkin skin) {
this.skin = skin; this.skin = skin;
DestroyEntitiesPacket destroyEntitiesPacket = new DestroyEntitiesPacket(); DestroyEntitiesPacket destroyEntitiesPacket = new DestroyEntitiesPacket();
@ -1090,6 +1094,7 @@ public class Player extends LivingEntity implements CommandSender {
* *
* @return the player username * @return the player username
*/ */
@NotNull
public String getUsername() { public String getUsername() {
return username; return username;
} }
@ -1100,11 +1105,11 @@ public class Player extends LivingEntity implements CommandSender {
* *
* @param username the new player name * @param username the new player name
*/ */
protected void setUsername(String username) { protected void setUsername(@NotNull String username) {
this.username = username; this.username = username;
} }
private void sendChangeGameStatePacket(ChangeGameStatePacket.Reason reason, float value) { private void sendChangeGameStatePacket(@NotNull ChangeGameStatePacket.Reason reason, float value) {
ChangeGameStatePacket changeGameStatePacket = new ChangeGameStatePacket(); ChangeGameStatePacket changeGameStatePacket = new ChangeGameStatePacket();
changeGameStatePacket.reason = reason; changeGameStatePacket.reason = reason;
changeGameStatePacket.value = value; changeGameStatePacket.value = value;
@ -1117,7 +1122,7 @@ public class Player extends LivingEntity implements CommandSender {
* @param item the item to drop * @param item the item to drop
* @return true if player can drop the item (event not cancelled), false otherwise * @return true if player can drop the item (event not cancelled), false otherwise
*/ */
public boolean dropItem(ItemStack item) { public boolean dropItem(@NotNull ItemStack item) {
ItemDropEvent itemDropEvent = new ItemDropEvent(item); ItemDropEvent itemDropEvent = new ItemDropEvent(item);
callEvent(ItemDropEvent.class, itemDropEvent); callEvent(ItemDropEvent.class, itemDropEvent);
return !itemDropEvent.isCancelled(); return !itemDropEvent.isCancelled();
@ -1145,7 +1150,7 @@ public class Player extends LivingEntity implements CommandSender {
* @param facePoint the point from where the player should aim * @param facePoint the point from where the player should aim
* @param targetPosition the target position to face * @param targetPosition the target position to face
*/ */
public void facePosition(FacePoint facePoint, Position targetPosition) { public void facePosition(@NotNull FacePoint facePoint, @NotNull Position targetPosition) {
facePosition(facePoint, targetPosition, null, null); facePosition(facePoint, targetPosition, null, null);
} }
@ -1156,11 +1161,11 @@ public class Player extends LivingEntity implements CommandSender {
* @param entity the entity to face * @param entity the entity to face
* @param targetPoint the point to aim at {@code entity} position * @param targetPoint the point to aim at {@code entity} position
*/ */
public void facePosition(FacePoint facePoint, Entity entity, FacePoint targetPoint) { public void facePosition(@NotNull FacePoint facePoint, Entity entity, FacePoint targetPoint) {
facePosition(facePoint, entity.getPosition(), entity, targetPoint); facePosition(facePoint, entity.getPosition(), entity, targetPoint);
} }
private void facePosition(FacePoint facePoint, Position targetPosition, Entity entity, FacePoint targetPoint) { private void facePosition(@NotNull FacePoint facePoint, @NotNull Position targetPosition, @Nullable Entity entity, @Nullable FacePoint targetPoint) {
FacePlayerPacket facePlayerPacket = new FacePlayerPacket(); FacePlayerPacket facePlayerPacket = new FacePlayerPacket();
facePlayerPacket.entityFacePosition = facePoint == FacePoint.EYE ? facePlayerPacket.entityFacePosition = facePoint == FacePoint.EYE ?
FacePlayerPacket.FacePosition.EYES : FacePlayerPacket.FacePosition.FEET; FacePlayerPacket.FacePosition.EYES : FacePlayerPacket.FacePosition.FEET;
@ -1180,7 +1185,7 @@ public class Player extends LivingEntity implements CommandSender {
* *
* @param entity the entity to spectate * @param entity the entity to spectate
*/ */
public void spectate(Entity entity) { public void spectate(@NotNull Entity entity) {
CameraPacket cameraPacket = new CameraPacket(); CameraPacket cameraPacket = new CameraPacket();
cameraPacket.cameraId = entity.getEntityId(); cameraPacket.cameraId = entity.getEntityId();
playerConnection.sendPacket(cameraPacket); playerConnection.sendPacket(cameraPacket);
@ -1200,6 +1205,7 @@ public class Player extends LivingEntity implements CommandSender {
* *
* @return the default respawn point * @return the default respawn point
*/ */
@NotNull
public Position getRespawnPoint() { public Position getRespawnPoint() {
return respawnPoint; return respawnPoint;
} }
@ -1209,7 +1215,7 @@ public class Player extends LivingEntity implements CommandSender {
* *
* @param respawnPoint the player respawn point * @param respawnPoint the player respawn point
*/ */
public void setRespawnPoint(Position respawnPoint) { public void setRespawnPoint(@NotNull Position respawnPoint) {
this.respawnPoint = respawnPoint; this.respawnPoint = respawnPoint;
} }
@ -1320,7 +1326,7 @@ public class Player extends LivingEntity implements CommandSender {
* *
* @param newChunk the current/new player chunk * @param newChunk the current/new player chunk
*/ */
protected void onChunkChange(Chunk newChunk) { protected void onChunkChange(@NotNull Chunk newChunk) {
// Previous chunks indexes // Previous chunks indexes
final long[] lastVisibleChunks = viewableChunks.stream().mapToLong(viewableChunks -> final long[] lastVisibleChunks = viewableChunks.stream().mapToLong(viewableChunks ->
ChunkUtils.getChunkIndex(viewableChunks.getChunkX(), viewableChunks.getChunkZ()) ChunkUtils.getChunkIndex(viewableChunks.getChunkX(), viewableChunks.getChunkZ())
@ -1368,7 +1374,7 @@ public class Player extends LivingEntity implements CommandSender {
} }
@Override @Override
public void teleport(Position position, Runnable callback) { public void teleport(@NotNull Position position, @Nullable Runnable callback) {
super.teleport(position, () -> { super.teleport(position, () -> {
updatePlayerPosition(); updatePlayerPosition();
OptionalCallback.execute(callback); OptionalCallback.execute(callback);
@ -1376,7 +1382,7 @@ public class Player extends LivingEntity implements CommandSender {
} }
@Override @Override
public void teleport(Position position) { public void teleport(@NotNull Position position) {
teleport(position, null); teleport(position, null);
} }
@ -1387,6 +1393,7 @@ public class Player extends LivingEntity implements CommandSender {
* *
* @return the player connection * @return the player connection
*/ */
@NotNull
public PlayerConnection getPlayerConnection() { public PlayerConnection getPlayerConnection() {
return playerConnection; return playerConnection;
} }
@ -1405,6 +1412,7 @@ public class Player extends LivingEntity implements CommandSender {
* *
* @return the player settings * @return the player settings
*/ */
@NotNull
public PlayerSettings getSettings() { public PlayerSettings getSettings() {
return settings; return settings;
} }
@ -1418,6 +1426,7 @@ public class Player extends LivingEntity implements CommandSender {
return dimensionType; return dimensionType;
} }
@NotNull
public PlayerInventory getInventory() { public PlayerInventory getInventory() {
return inventory; return inventory;
} }
@ -1446,7 +1455,7 @@ public class Player extends LivingEntity implements CommandSender {
* *
* @param gameMode the new player GameMode * @param gameMode the new player GameMode
*/ */
public void setGameMode(GameMode gameMode) { public void setGameMode(@NotNull GameMode gameMode) {
Check.notNull(gameMode, "GameMode cannot be null"); Check.notNull(gameMode, "GameMode cannot be null");
this.gameMode = gameMode; this.gameMode = gameMode;
sendChangeGameStatePacket(ChangeGameStatePacket.Reason.CHANGE_GAMEMODE, gameMode.getId()); sendChangeGameStatePacket(ChangeGameStatePacket.Reason.CHANGE_GAMEMODE, gameMode.getId());
@ -1471,7 +1480,7 @@ public class Player extends LivingEntity implements CommandSender {
* *
* @param dimensionType the new player dimension * @param dimensionType the new player dimension
*/ */
protected void sendDimension(DimensionType dimensionType) { protected void sendDimension(@NotNull DimensionType dimensionType) {
Check.notNull(dimensionType, "Dimension cannot be null!"); Check.notNull(dimensionType, "Dimension cannot be null!");
Check.argCondition(dimensionType.equals(getDimensionType()), "The dimension needs to be different than the current one!"); Check.argCondition(dimensionType.equals(getDimensionType()), "The dimension needs to be different than the current one!");
@ -1488,7 +1497,7 @@ public class Player extends LivingEntity implements CommandSender {
* *
* @param text the kick reason * @param text the kick reason
*/ */
public void kick(ColoredText text) { public void kick(@NotNull ColoredText text) {
DisconnectPacket disconnectPacket = new DisconnectPacket(); DisconnectPacket disconnectPacket = new DisconnectPacket();
disconnectPacket.message = text; disconnectPacket.message = text;
playerConnection.sendPacket(disconnectPacket); playerConnection.sendPacket(disconnectPacket);
@ -1501,7 +1510,7 @@ public class Player extends LivingEntity implements CommandSender {
* *
* @param message the kick reason * @param message the kick reason
*/ */
public void kick(String message) { public void kick(@NotNull String message) {
kick(ColoredText.of(message)); kick(ColoredText.of(message));
} }
@ -1581,6 +1590,7 @@ public class Player extends LivingEntity implements CommandSender {
* *
* @return the currently mined {@link CustomBlock} by the player, null if there is not * @return the currently mined {@link CustomBlock} by the player, null if there is not
*/ */
@Nullable
public CustomBlock getCustomBlockTarget() { public CustomBlock getCustomBlockTarget() {
return targetCustomBlock; return targetCustomBlock;
} }
@ -1590,6 +1600,7 @@ public class Player extends LivingEntity implements CommandSender {
* *
* @return the currently open inventory, null if there is not (player inventory is not detected) * @return the currently open inventory, null if there is not (player inventory is not detected)
*/ */
@Nullable
public Inventory getOpenInventory() { public Inventory getOpenInventory() {
return openInventory; return openInventory;
} }
@ -1600,7 +1611,7 @@ public class Player extends LivingEntity implements CommandSender {
* @param inventory the inventory to open * @param inventory the inventory to open
* @return true if the inventory has been opened/sent to the player, false otherwise (cancelled by event) * @return true if the inventory has been opened/sent to the player, false otherwise (cancelled by event)
*/ */
public boolean openInventory(Inventory inventory) { public boolean openInventory(@NotNull Inventory inventory) {
Check.notNull(inventory, "Inventory cannot be null, use Player#closeInventory() to close current"); Check.notNull(inventory, "Inventory cannot be null, use Player#closeInventory() to close current");
InventoryOpenEvent inventoryOpenEvent = new InventoryOpenEvent(this, inventory); InventoryOpenEvent inventoryOpenEvent = new InventoryOpenEvent(this, inventory);
@ -1702,7 +1713,7 @@ public class Player extends LivingEntity implements CommandSender {
* *
* @param chunk the chunk to update the view * @param chunk the chunk to update the view
*/ */
public void updateViewPosition(Chunk chunk) { public void updateViewPosition(@NotNull Chunk chunk) {
UpdateViewPositionPacket updateViewPositionPacket = new UpdateViewPositionPacket(); UpdateViewPositionPacket updateViewPositionPacket = new UpdateViewPositionPacket();
updateViewPositionPacket.chunkX = chunk.getChunkX(); updateViewPositionPacket.chunkX = chunk.getChunkX();
updateViewPositionPacket.chunkZ = chunk.getChunkZ(); updateViewPositionPacket.chunkZ = chunk.getChunkZ();

View File

@ -7,6 +7,7 @@ import net.minestom.server.entity.type.decoration.EntityArmorStand;
import net.minestom.server.instance.Instance; import net.minestom.server.instance.Instance;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import net.minestom.server.utils.validate.Check; import net.minestom.server.utils.validate.Check;
import org.jetbrains.annotations.NotNull;
import java.util.Set; import java.util.Set;
@ -105,15 +106,16 @@ public class Hologram implements Viewable {
} }
@Override @Override
public boolean addViewer(Player player) { public boolean addViewer(@NotNull Player player) {
return entity.addViewer(player); return entity.addViewer(player);
} }
@Override @Override
public boolean removeViewer(Player player) { public boolean removeViewer(@NotNull Player player) {
return entity.removeViewer(player); return entity.removeViewer(player);
} }
@NotNull
@Override @Override
public Set<Player> getViewers() { public Set<Player> getViewers() {
return entity.getViewers(); return entity.getViewers();

View File

@ -5,6 +5,7 @@ import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.type.Animal; import net.minestom.server.entity.type.Animal;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -17,6 +18,7 @@ public class EntityBat extends EntityCreature implements Animal {
setBoundingBox(0.5f, 0.9f, 0.5f); setBoundingBox(0.5f, 0.9f, 0.5f);
} }
@NotNull
@Override @Override
public Consumer<BinaryWriter> getMetadataConsumer() { public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> { return packet -> {
@ -26,7 +28,7 @@ public class EntityBat extends EntityCreature implements Animal {
} }
@Override @Override
protected void fillMetadataIndex(BinaryWriter packet, int index) { protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
super.fillMetadataIndex(packet, index); super.fillMetadataIndex(packet, index);
if (index == 15) { if (index == 15) {
packet.writeByte((byte) 15); packet.writeByte((byte) 15);

View File

@ -19,6 +19,7 @@ public class EntityMooshroom extends EntityCreature implements Animal {
setMooshroomType(MooshroomType.RED); setMooshroomType(MooshroomType.RED);
} }
@NotNull
@Override @Override
public Consumer<BinaryWriter> getMetadataConsumer() { public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> { return packet -> {
@ -28,7 +29,7 @@ public class EntityMooshroom extends EntityCreature implements Animal {
} }
@Override @Override
protected void fillMetadataIndex(BinaryWriter packet, int index) { protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
super.fillMetadataIndex(packet, index); super.fillMetadataIndex(packet, index);
if (index == 16) { if (index == 16) {
packet.writeByte((byte) 16); packet.writeByte((byte) 16);

View File

@ -5,6 +5,7 @@ import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.type.Animal; import net.minestom.server.entity.type.Animal;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -17,6 +18,7 @@ public class EntityPig extends EntityCreature implements Animal {
setBoundingBox(0.9f, 0.9f, 0.9f); setBoundingBox(0.9f, 0.9f, 0.9f);
} }
@NotNull
@Override @Override
public Consumer<BinaryWriter> getMetadataConsumer() { public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> { return packet -> {
@ -26,7 +28,7 @@ public class EntityPig extends EntityCreature implements Animal {
} }
@Override @Override
protected void fillMetadataIndex(BinaryWriter packet, int index) { protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
super.fillMetadataIndex(packet, index); super.fillMetadataIndex(packet, index);
if (index == 16) { if (index == 16) {
packet.writeByte((byte) 16); packet.writeByte((byte) 16);

View File

@ -5,6 +5,7 @@ import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.type.Animal; import net.minestom.server.entity.type.Animal;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -17,6 +18,7 @@ public class EntityPolarBear extends EntityCreature implements Animal {
setBoundingBox(1.3f, 1.4f, 1.3f); setBoundingBox(1.3f, 1.4f, 1.3f);
} }
@NotNull
@Override @Override
public Consumer<BinaryWriter> getMetadataConsumer() { public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> { return packet -> {
@ -26,7 +28,7 @@ public class EntityPolarBear extends EntityCreature implements Animal {
} }
@Override @Override
protected void fillMetadataIndex(BinaryWriter packet, int index) { protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
super.fillMetadataIndex(packet, index); super.fillMetadataIndex(packet, index);
if (index == 16) { if (index == 16) {
packet.writeByte((byte) 16); packet.writeByte((byte) 16);

View File

@ -5,6 +5,7 @@ import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.type.Animal; import net.minestom.server.entity.type.Animal;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -17,6 +18,7 @@ public class EntityRabbit extends EntityCreature implements Animal {
setBoundingBox(0.4f, 0.5f, 0.4f); setBoundingBox(0.4f, 0.5f, 0.4f);
} }
@NotNull
@Override @Override
public Consumer<BinaryWriter> getMetadataConsumer() { public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> { return packet -> {
@ -26,7 +28,7 @@ public class EntityRabbit extends EntityCreature implements Animal {
} }
@Override @Override
protected void fillMetadataIndex(BinaryWriter packet, int index) { protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
super.fillMetadataIndex(packet, index); super.fillMetadataIndex(packet, index);
if (index == 16) { if (index == 16) {
packet.writeByte((byte) 16); packet.writeByte((byte) 16);

View File

@ -11,6 +11,7 @@ import net.minestom.server.utils.Position;
import net.minestom.server.utils.Vector; import net.minestom.server.utils.Vector;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import net.minestom.server.utils.item.ItemStackUtils; import net.minestom.server.utils.item.ItemStackUtils;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -61,7 +62,7 @@ public class EntityArmorStand extends ObjectEntity implements EquipmentHandler {
} }
@Override @Override
public boolean addViewer(Player player) { public boolean addViewer(@NotNull Player player) {
boolean result = super.addViewer(player); boolean result = super.addViewer(player);
syncEquipments(player.getPlayerConnection()); syncEquipments(player.getPlayerConnection());
return result; return result;
@ -72,6 +73,7 @@ public class EntityArmorStand extends ObjectEntity implements EquipmentHandler {
return 0; return 0;
} }
@NotNull
@Override @Override
public Consumer<BinaryWriter> getMetadataConsumer() { public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> { return packet -> {
@ -87,7 +89,7 @@ public class EntityArmorStand extends ObjectEntity implements EquipmentHandler {
} }
@Override @Override
protected void fillMetadataIndex(BinaryWriter packet, int index) { protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
super.fillMetadataIndex(packet, index); super.fillMetadataIndex(packet, index);
if (index == 14) { if (index == 14) {
packet.writeByte((byte) 14); packet.writeByte((byte) 14);

View File

@ -7,6 +7,7 @@ import net.minestom.server.utils.Position;
import net.minestom.server.utils.Rotation; import net.minestom.server.utils.Rotation;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import net.minestom.server.utils.item.ItemStackUtils; import net.minestom.server.utils.item.ItemStackUtils;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -26,6 +27,7 @@ public class EntityItemFrame extends ObjectEntity {
setGravity(0f); setGravity(0f);
} }
@NotNull
@Override @Override
public Consumer<BinaryWriter> getMetadataConsumer() { public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> { return packet -> {
@ -36,7 +38,7 @@ public class EntityItemFrame extends ObjectEntity {
} }
@Override @Override
protected void fillMetadataIndex(BinaryWriter packet, int index) { protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
super.fillMetadataIndex(packet, index); super.fillMetadataIndex(packet, index);
if (index == 7) { if (index == 7) {
packet.writeByte((byte) 7); packet.writeByte((byte) 7);

View File

@ -5,6 +5,7 @@ import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.type.Monster; import net.minestom.server.entity.type.Monster;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -15,6 +16,7 @@ public class EntityBlaze extends EntityCreature implements Monster {
setBoundingBox(0.6f, 1.8f, 0.6f); setBoundingBox(0.6f, 1.8f, 0.6f);
} }
@NotNull
@Override @Override
public Consumer<BinaryWriter> getMetadataConsumer() { public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> { return packet -> {
@ -24,7 +26,7 @@ public class EntityBlaze extends EntityCreature implements Monster {
} }
@Override @Override
protected void fillMetadataIndex(BinaryWriter packet, int index) { protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
super.fillMetadataIndex(packet, index); super.fillMetadataIndex(packet, index);
if (index == 15) { if (index == 15) {
packet.writeByte((byte) 15); packet.writeByte((byte) 15);

View File

@ -5,6 +5,7 @@ import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.type.Monster; import net.minestom.server.entity.type.Monster;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -19,6 +20,7 @@ public class EntityCreeper extends EntityCreature implements Monster {
setBoundingBox(0.6f, 1.7f, 0.6f); setBoundingBox(0.6f, 1.7f, 0.6f);
} }
@NotNull
@Override @Override
public Consumer<BinaryWriter> getMetadataConsumer() { public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> { return packet -> {
@ -28,7 +30,7 @@ public class EntityCreeper extends EntityCreature implements Monster {
} }
@Override @Override
protected void fillMetadataIndex(BinaryWriter packet, int index) { protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
super.fillMetadataIndex(packet, index); super.fillMetadataIndex(packet, index);
if (index == 15) { if (index == 15) {
packet.writeByte((byte) 15); packet.writeByte((byte) 15);

View File

@ -5,6 +5,7 @@ import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.type.Monster; import net.minestom.server.entity.type.Monster;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -18,6 +19,7 @@ public class EntityGhast extends EntityCreature implements Monster {
setEyeHeight(2.6f); setEyeHeight(2.6f);
} }
@NotNull
@Override @Override
public Consumer<BinaryWriter> getMetadataConsumer() { public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> { return packet -> {
@ -27,7 +29,7 @@ public class EntityGhast extends EntityCreature implements Monster {
} }
@Override @Override
protected void fillMetadataIndex(BinaryWriter packet, int index) { protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
super.fillMetadataIndex(packet, index); super.fillMetadataIndex(packet, index);
if (index == 15) { if (index == 15) {
packet.writeByte((byte) 15); packet.writeByte((byte) 15);

View File

@ -6,6 +6,7 @@ import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.type.Monster; import net.minestom.server.entity.type.Monster;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -19,6 +20,7 @@ public class EntityGuardian extends EntityCreature implements Monster {
setBoundingBox(0.85f, 0.85f, 0.85f); setBoundingBox(0.85f, 0.85f, 0.85f);
} }
@NotNull
@Override @Override
public Consumer<BinaryWriter> getMetadataConsumer() { public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> { return packet -> {
@ -29,7 +31,7 @@ public class EntityGuardian extends EntityCreature implements Monster {
} }
@Override @Override
protected void fillMetadataIndex(BinaryWriter packet, int index) { protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
super.fillMetadataIndex(packet, index); super.fillMetadataIndex(packet, index);
if (index == 15) { if (index == 15) {
packet.writeByte((byte) 15); packet.writeByte((byte) 15);

View File

@ -5,6 +5,7 @@ import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.type.Monster; import net.minestom.server.entity.type.Monster;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -17,6 +18,7 @@ public class EntityPhantom extends EntityCreature implements Monster {
setBoundingBox(0.9f, 0.5f, 0.9f); // TODO change based on size setBoundingBox(0.9f, 0.5f, 0.9f); // TODO change based on size
} }
@NotNull
@Override @Override
public Consumer<BinaryWriter> getMetadataConsumer() { public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> { return packet -> {
@ -26,7 +28,7 @@ public class EntityPhantom extends EntityCreature implements Monster {
} }
@Override @Override
protected void fillMetadataIndex(BinaryWriter packet, int index) { protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
super.fillMetadataIndex(packet, index); super.fillMetadataIndex(packet, index);
if (index == 15) { if (index == 15) {
packet.writeByte((byte) 15); packet.writeByte((byte) 15);

View File

@ -5,6 +5,7 @@ import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.type.Monster; import net.minestom.server.entity.type.Monster;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -17,6 +18,7 @@ public class EntitySlime extends EntityCreature implements Monster {
setSize(1); setSize(1);
} }
@NotNull
@Override @Override
public Consumer<BinaryWriter> getMetadataConsumer() { public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> { return packet -> {
@ -26,7 +28,7 @@ public class EntitySlime extends EntityCreature implements Monster {
} }
@Override @Override
protected void fillMetadataIndex(BinaryWriter packet, int index) { protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
super.fillMetadataIndex(packet, index); super.fillMetadataIndex(packet, index);
if (index == 15) { if (index == 15) {
packet.writeByte((byte) 15); packet.writeByte((byte) 15);

View File

@ -5,6 +5,7 @@ import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.type.Monster; import net.minestom.server.entity.type.Monster;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -18,6 +19,7 @@ public class EntitySpider extends EntityCreature implements Monster {
setEyeHeight(0.65f); setEyeHeight(0.65f);
} }
@NotNull
@Override @Override
public Consumer<BinaryWriter> getMetadataConsumer() { public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> { return packet -> {
@ -27,7 +29,7 @@ public class EntitySpider extends EntityCreature implements Monster {
} }
@Override @Override
protected void fillMetadataIndex(BinaryWriter packet, int index) { protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
super.fillMetadataIndex(packet, index); super.fillMetadataIndex(packet, index);
if (index == 15) { if (index == 15) {
packet.writeByte((byte) 15); packet.writeByte((byte) 15);

View File

@ -5,6 +5,7 @@ import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.type.Monster; import net.minestom.server.entity.type.Monster;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -18,6 +19,7 @@ public class EntityWitch extends EntityCreature implements Monster {
setEyeHeight(1.62f); setEyeHeight(1.62f);
} }
@NotNull
@Override @Override
public Consumer<BinaryWriter> getMetadataConsumer() { public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> { return packet -> {
@ -27,7 +29,7 @@ public class EntityWitch extends EntityCreature implements Monster {
} }
@Override @Override
protected void fillMetadataIndex(BinaryWriter packet, int index) { protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
super.fillMetadataIndex(packet, index); super.fillMetadataIndex(packet, index);
if (index == 16) { if (index == 16) {
packet.writeByte((byte) 16); packet.writeByte((byte) 16);

View File

@ -5,6 +5,7 @@ import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.type.Monster; import net.minestom.server.entity.type.Monster;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -18,6 +19,7 @@ public class EntityZombie extends EntityCreature implements Monster {
setBoundingBox(0.6f, 1.95f, 0.6f); setBoundingBox(0.6f, 1.95f, 0.6f);
} }
@NotNull
@Override @Override
public Consumer<BinaryWriter> getMetadataConsumer() { public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> { return packet -> {
@ -28,7 +30,7 @@ public class EntityZombie extends EntityCreature implements Monster {
} }
@Override @Override
protected void fillMetadataIndex(BinaryWriter packet, int index) { protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
super.fillMetadataIndex(packet, index); super.fillMetadataIndex(packet, index);
if (index == 15) { if (index == 15) {
packet.writeByte((byte) 15); packet.writeByte((byte) 15);

View File

@ -5,6 +5,7 @@ import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.type.Monster; import net.minestom.server.entity.type.Monster;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -18,6 +19,7 @@ public class EntityZombifiedPiglin extends EntityCreature implements Monster {
setBoundingBox(0.6f, 1.95f, 0.6f); setBoundingBox(0.6f, 1.95f, 0.6f);
} }
@NotNull
@Override @Override
public Consumer<BinaryWriter> getMetadataConsumer() { public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> { return packet -> {
@ -28,7 +30,7 @@ public class EntityZombifiedPiglin extends EntityCreature implements Monster {
} }
@Override @Override
protected void fillMetadataIndex(BinaryWriter packet, int index) { protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
super.fillMetadataIndex(packet, index); super.fillMetadataIndex(packet, index);
if (index == 15) { if (index == 15) {
packet.writeByte((byte) 15); packet.writeByte((byte) 15);

View File

@ -5,6 +5,7 @@ import net.minestom.server.entity.ObjectEntity;
import net.minestom.server.particle.Particle; import net.minestom.server.particle.Particle;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -26,6 +27,7 @@ public class EntityAreaEffectCloud extends ObjectEntity {
}); });
} }
@NotNull
@Override @Override
public Consumer<BinaryWriter> getMetadataConsumer() { public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> { return packet -> {
@ -38,7 +40,7 @@ public class EntityAreaEffectCloud extends ObjectEntity {
} }
@Override @Override
protected void fillMetadataIndex(BinaryWriter packet, int index) { protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
super.fillMetadataIndex(packet, index); super.fillMetadataIndex(packet, index);
if (index == 7) { if (index == 7) {
packet.writeByte((byte) 7); packet.writeByte((byte) 7);

View File

@ -5,6 +5,7 @@ import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.type.Constructable; import net.minestom.server.entity.type.Constructable;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -17,6 +18,7 @@ public class EntityIronGolem extends EntityCreature implements Constructable {
setBoundingBox(1.4f, 2.7f, 1.4f); setBoundingBox(1.4f, 2.7f, 1.4f);
} }
@NotNull
@Override @Override
public Consumer<BinaryWriter> getMetadataConsumer() { public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> { return packet -> {
@ -26,7 +28,7 @@ public class EntityIronGolem extends EntityCreature implements Constructable {
} }
@Override @Override
protected void fillMetadataIndex(BinaryWriter packet, int index) { protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
super.fillMetadataIndex(packet, index); super.fillMetadataIndex(packet, index);
if (index == 15) { if (index == 15) {
packet.writeByte((byte) 15); packet.writeByte((byte) 15);

View File

@ -5,6 +5,7 @@ import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.type.Constructable; import net.minestom.server.entity.type.Constructable;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -17,6 +18,7 @@ public class EntitySnowman extends EntityCreature implements Constructable {
setBoundingBox(0.7f, 1.9f, 0.7f); setBoundingBox(0.7f, 1.9f, 0.7f);
} }
@NotNull
@Override @Override
public Consumer<BinaryWriter> getMetadataConsumer() { public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> { return packet -> {
@ -26,7 +28,7 @@ public class EntitySnowman extends EntityCreature implements Constructable {
} }
@Override @Override
protected void fillMetadataIndex(BinaryWriter packet, int index) { protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
super.fillMetadataIndex(packet, index); super.fillMetadataIndex(packet, index);
if (index == 15) { if (index == 15) {
packet.writeByte((byte) 15); packet.writeByte((byte) 15);

View File

@ -7,6 +7,7 @@ import net.minestom.server.item.ItemStack;
import net.minestom.server.item.Material; import net.minestom.server.item.Material;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -18,6 +19,7 @@ public class EntityEyeOfEnder extends ObjectEntity implements Projectile {
super(EntityType.EYE_OF_ENDER, spawnPosition); super(EntityType.EYE_OF_ENDER, spawnPosition);
} }
@NotNull
@Override @Override
public Consumer<BinaryWriter> getMetadataConsumer() { public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> { return packet -> {
@ -27,7 +29,7 @@ public class EntityEyeOfEnder extends ObjectEntity implements Projectile {
} }
@Override @Override
protected void fillMetadataIndex(BinaryWriter packet, int index) { protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
super.fillMetadataIndex(packet, index); super.fillMetadataIndex(packet, index);
if (index == 7) { if (index == 7) {
packet.writeByte((byte) 7); packet.writeByte((byte) 7);

View File

@ -6,6 +6,7 @@ import net.minestom.server.entity.type.Projectile;
import net.minestom.server.item.ItemStack; import net.minestom.server.item.ItemStack;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -19,6 +20,7 @@ public class EntityPotion extends ObjectEntity implements Projectile {
setPotion(potion); setPotion(potion);
} }
@NotNull
@Override @Override
public Consumer<BinaryWriter> getMetadataConsumer() { public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> { return packet -> {
@ -28,7 +30,7 @@ public class EntityPotion extends ObjectEntity implements Projectile {
} }
@Override @Override
protected void fillMetadataIndex(BinaryWriter packet, int index) { protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
super.fillMetadataIndex(packet, index); super.fillMetadataIndex(packet, index);
if (index == 7) { if (index == 7) {
packet.writeByte((byte) 7); packet.writeByte((byte) 7);

View File

@ -6,6 +6,7 @@ import net.minestom.server.entity.type.Vehicle;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.binary.BinaryWriter;
import net.minestom.server.utils.validate.Check; import net.minestom.server.utils.validate.Check;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer; import java.util.function.Consumer;
@ -26,6 +27,7 @@ public class EntityBoat extends ObjectEntity implements Vehicle {
return 0; return 0;
} }
@NotNull
@Override @Override
public Consumer<BinaryWriter> getMetadataConsumer() { public Consumer<BinaryWriter> getMetadataConsumer() {
return packet -> { return packet -> {
@ -39,7 +41,7 @@ public class EntityBoat extends ObjectEntity implements Vehicle {
} }
@Override @Override
protected void fillMetadataIndex(BinaryWriter packet, int index) { protected void fillMetadataIndex(@NotNull BinaryWriter packet, int index) {
super.fillMetadataIndex(packet, index); super.fillMetadataIndex(packet, index);
if (index == 10) { if (index == 10) {
packet.writeByte((byte) 10); packet.writeByte((byte) 10);

View File

@ -27,6 +27,8 @@ import net.minestom.server.utils.player.PlayerUtils;
import net.minestom.server.utils.validate.Check; import net.minestom.server.utils.validate.Check;
import net.minestom.server.world.biomes.Biome; import net.minestom.server.world.biomes.Biome;
import net.minestom.server.world.biomes.BiomeManager; import net.minestom.server.world.biomes.BiomeManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*; import java.util.*;
import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.CopyOnWriteArraySet;
@ -79,7 +81,7 @@ public abstract class Chunk implements Viewable, DataContainer {
// Data // Data
protected Data data; protected Data data;
public Chunk(Instance instance, Biome[] biomes, int chunkX, int chunkZ, boolean shouldGenerate) { public Chunk(@NotNull Instance instance, @Nullable Biome[] biomes, int chunkX, int chunkZ, boolean shouldGenerate) {
this.instance = instance; this.instance = instance;
this.chunkX = chunkX; this.chunkX = chunkX;
this.chunkZ = chunkZ; this.chunkZ = chunkZ;
@ -114,7 +116,7 @@ public abstract class Chunk implements Viewable, DataContainer {
* Warning: <code>customBlockId</code> cannot be 0 and needs to be valid since the update delay and method * Warning: <code>customBlockId</code> cannot be 0 and needs to be valid since the update delay and method
* will be retrieved from the associated {@link CustomBlock} object * will be retrieved from the associated {@link CustomBlock} object
*/ */
public abstract void UNSAFE_setBlock(int x, int y, int z, short blockStateId, short customBlockId, Data data, boolean updatable); public abstract void UNSAFE_setBlock(int x, int y, int z, short blockStateId, short customBlockId, @Nullable Data data, boolean updatable);
/** /**
* Executes a chunk tick. * Executes a chunk tick.
@ -126,7 +128,7 @@ public abstract class Chunk implements Viewable, DataContainer {
* @param time the time of the update in milliseconds * @param time the time of the update in milliseconds
* @param instance the {@link Instance} linked to this chunk * @param instance the {@link Instance} linked to this chunk
*/ */
public abstract void tick(long time, Instance instance); public abstract void tick(long time, @NotNull Instance instance);
/** /**
* Gets the block state id at a position. * Gets the block state id at a position.
@ -175,6 +177,7 @@ public abstract class Chunk implements Viewable, DataContainer {
* @param index the block index * @param index the block index
* @return the {@link Data} at the block index, null if none * @return the {@link Data} at the block index, null if none
*/ */
@Nullable
public abstract Data getBlockData(int index); public abstract Data getBlockData(int index);
/** /**
@ -192,6 +195,7 @@ public abstract class Chunk implements Viewable, DataContainer {
* *
* @return the block entities in this chunk * @return the block entities in this chunk
*/ */
@NotNull
public abstract Set<Integer> getBlockEntities(); public abstract Set<Integer> getBlockEntities();
/** /**
@ -210,17 +214,18 @@ public abstract class Chunk implements Viewable, DataContainer {
* @param reader the data reader * @param reader the data reader
* WARNING: the data will not necessary be read directly in the same thread, * WARNING: the data will not necessary be read directly in the same thread,
* be sure that the data is only used for this reading. * be sure that the data is only used for this reading.
* @param callback the callback to execute once the chunk is done reading * @param callback the optional callback to execute once the chunk is done reading
* WARNING: this need to be called to notify the instance. * WARNING: this need to be called to notify the instance.
* @see #getSerializedData() which is responsible for the serialized data given * @see #getSerializedData() which is responsible for the serialized data given
*/ */
public abstract void readChunk(BinaryReader reader, ChunkCallback callback); public abstract void readChunk(@NotNull BinaryReader reader, @Nullable ChunkCallback callback);
/** /**
* Creates a {@link ChunkDataPacket} with this chunk data ready to be written. * Creates a {@link ChunkDataPacket} with this chunk data ready to be written.
* *
* @return a new chunk data packet * @return a new chunk data packet
*/ */
@NotNull
protected abstract ChunkDataPacket createFreshPacket(); protected abstract ChunkDataPacket createFreshPacket();
/** /**
@ -395,6 +400,7 @@ public abstract class Chunk implements Viewable, DataContainer {
* *
* @return a fresh non-full chunk data packet * @return a fresh non-full chunk data packet
*/ */
@NotNull
public ChunkDataPacket getFreshPartialDataPacket() { public ChunkDataPacket getFreshPartialDataPacket() {
ChunkDataPacket fullDataPacket = createFreshPacket(); ChunkDataPacket fullDataPacket = createFreshPacket();
fullDataPacket.fullChunk = false; fullDataPacket.fullChunk = false;
@ -423,7 +429,7 @@ public abstract class Chunk implements Viewable, DataContainer {
* @return true if the player has just been added to the viewer collection * @return true if the player has just been added to the viewer collection
*/ */
@Override @Override
public boolean addViewer(Player player) { public boolean addViewer(@NotNull Player player) {
final boolean result = this.viewers.add(player); final boolean result = this.viewers.add(player);
// Send the chunk data & light packets to the player // Send the chunk data & light packets to the player
@ -444,7 +450,7 @@ public abstract class Chunk implements Viewable, DataContainer {
* @return true if the player has just been removed to the viewer collection * @return true if the player has just been removed to the viewer collection
*/ */
@Override @Override
public boolean removeViewer(Player player) { public boolean removeViewer(@NotNull Player player) {
final boolean result = this.viewers.remove(player); final boolean result = this.viewers.remove(player);
// Remove from the viewable chunks set // Remove from the viewable chunks set
@ -455,6 +461,7 @@ public abstract class Chunk implements Viewable, DataContainer {
return result; return result;
} }
@NotNull
@Override @Override
public Set<Player> getViewers() { public Set<Player> getViewers() {
return Collections.unmodifiableSet(viewers); return Collections.unmodifiableSet(viewers);
@ -563,6 +570,7 @@ public abstract class Chunk implements Viewable, DataContainer {
* @param section the chunk section to update * @param section the chunk section to update
* @return the {@link ChunkDataPacket} to update a single chunk section * @return the {@link ChunkDataPacket} to update a single chunk section
*/ */
@NotNull
protected ChunkDataPacket getChunkSectionUpdatePacket(int section) { protected ChunkDataPacket getChunkSectionUpdatePacket(int section) {
ChunkDataPacket chunkDataPacket = getFreshPartialDataPacket(); ChunkDataPacket chunkDataPacket = getFreshPartialDataPacket();
chunkDataPacket.fullChunk = false; chunkDataPacket.fullChunk = false;

View File

@ -23,6 +23,7 @@ import net.minestom.server.utils.time.CooldownUtils;
import net.minestom.server.utils.time.UpdateOption; import net.minestom.server.utils.time.UpdateOption;
import net.minestom.server.utils.validate.Check; import net.minestom.server.utils.validate.Check;
import net.minestom.server.world.biomes.Biome; import net.minestom.server.world.biomes.Biome;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -123,7 +124,7 @@ public class DynamicChunk extends Chunk {
} }
@Override @Override
public void tick(long time, Instance instance) { public void tick(long time, @NotNull Instance instance) {
if (updatableBlocks.isEmpty()) if (updatableBlocks.isEmpty())
return; return;
@ -202,6 +203,7 @@ public class DynamicChunk extends Chunk {
} }
} }
@NotNull
@Override @Override
public Set<Integer> getBlockEntities() { public Set<Integer> getBlockEntities() {
return blockEntities; return blockEntities;
@ -302,7 +304,7 @@ public class DynamicChunk extends Chunk {
} }
@Override @Override
public void readChunk(BinaryReader reader, ChunkCallback callback) { public void readChunk(@NotNull BinaryReader reader, ChunkCallback callback) {
// Check the buffer length // Check the buffer length
final int length = reader.available(); final int length = reader.available();
Check.argCondition(length == 0, "The length of the buffer must be > 0"); Check.argCondition(length == 0, "The length of the buffer must be > 0");
@ -385,6 +387,7 @@ public class DynamicChunk extends Chunk {
}).schedule(); }).schedule();
} }
@NotNull
@Override @Override
protected ChunkDataPacket createFreshPacket() { protected ChunkDataPacket createFreshPacket() {
ChunkDataPacket fullDataPacket = new ChunkDataPacket(); ChunkDataPacket fullDataPacket = new ChunkDataPacket();

View File

@ -4,6 +4,8 @@ import net.minestom.server.MinecraftServer;
import net.minestom.server.utils.callback.OptionalCallback; import net.minestom.server.utils.callback.OptionalCallback;
import net.minestom.server.utils.chunk.ChunkCallback; import net.minestom.server.utils.chunk.ChunkCallback;
import net.minestom.server.utils.thread.MinestomThread; import net.minestom.server.utils.thread.MinestomThread;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection; import java.util.Collection;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@ -26,7 +28,7 @@ public interface IChunkLoader {
* never called if the method returns false. Can be null. * never called if the method returns false. Can be null.
* @return true if the chunk loaded successfully, false otherwise * @return true if the chunk loaded successfully, false otherwise
*/ */
boolean loadChunk(Instance instance, int chunkX, int chunkZ, ChunkCallback callback); boolean loadChunk(@NotNull Instance instance, int chunkX, int chunkZ, @Nullable ChunkCallback callback);
/** /**
* Saves a {@link Chunk} with an optional callback for when it is done. * Saves a {@link Chunk} with an optional callback for when it is done.
@ -36,7 +38,7 @@ public interface IChunkLoader {
* should be called even if the saving failed (you can throw an exception). * should be called even if the saving failed (you can throw an exception).
* Can be null. * Can be null.
*/ */
void saveChunk(Chunk chunk, Runnable callback); void saveChunk(@NotNull Chunk chunk, @Nullable Runnable callback);
/** /**
* Saves multiple chunks with an optional callback for when it is done. * Saves multiple chunks with an optional callback for when it is done.
@ -48,7 +50,7 @@ public interface IChunkLoader {
* should be called even if the saving failed (you can throw an exception). * should be called even if the saving failed (you can throw an exception).
* Can be null. * Can be null.
*/ */
default void saveChunks(Collection<Chunk> chunks, Runnable callback) { default void saveChunks(@NotNull Collection<Chunk> chunks, @Nullable Runnable callback) {
if (supportsParallelSaving()) { if (supportsParallelSaving()) {
ExecutorService parallelSavingThreadPool = new MinestomThread(MinecraftServer.THREAD_COUNT_PARALLEL_CHUNK_SAVING, MinecraftServer.THREAD_NAME_PARALLEL_CHUNK_SAVING, true); ExecutorService parallelSavingThreadPool = new MinestomThread(MinecraftServer.THREAD_COUNT_PARALLEL_CHUNK_SAVING, MinecraftServer.THREAD_NAME_PARALLEL_CHUNK_SAVING, true);
chunks.forEach(c -> parallelSavingThreadPool.execute(() -> saveChunk(c, null))); chunks.forEach(c -> parallelSavingThreadPool.execute(() -> saveChunk(c, null)));

View File

@ -30,6 +30,8 @@ import net.minestom.server.utils.time.TimeUnit;
import net.minestom.server.utils.time.UpdateOption; import net.minestom.server.utils.time.UpdateOption;
import net.minestom.server.utils.validate.Check; import net.minestom.server.utils.validate.Check;
import net.minestom.server.world.DimensionType; import net.minestom.server.world.DimensionType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -145,7 +147,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* @param callback optional consumer called after the chunk has been generated, * @param callback optional consumer called after the chunk has been generated,
* the returned chunk will never be null * the returned chunk will never be null
*/ */
public abstract void loadChunk(int chunkX, int chunkZ, ChunkCallback callback); public abstract void loadChunk(int chunkX, int chunkZ, @Nullable ChunkCallback callback);
/** /**
* Loads the chunk if the chunk is already loaded or if * Loads the chunk if the chunk is already loaded or if
@ -156,7 +158,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* @param callback optional consumer called after the chunk has tried to be loaded, * @param callback optional consumer called after the chunk has tried to be loaded,
* contains a chunk if it is successful, null otherwise * contains a chunk if it is successful, null otherwise
*/ */
public abstract void loadOptionalChunk(int chunkX, int chunkZ, ChunkCallback callback); public abstract void loadOptionalChunk(int chunkX, int chunkZ, @Nullable ChunkCallback callback);
/** /**
* Schedules the removal of a {@link Chunk}, this method does not promise when it will be done. * Schedules the removal of a {@link Chunk}, this method does not promise when it will be done.
@ -167,7 +169,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* *
* @param chunk the chunk to unload * @param chunk the chunk to unload
*/ */
public abstract void unloadChunk(Chunk chunk); public abstract void unloadChunk(@NotNull Chunk chunk);
/** /**
* Gets the loaded {@link Chunk} at a position. * Gets the loaded {@link Chunk} at a position.
@ -178,6 +180,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* @param chunkZ the chunk Z * @param chunkZ the chunk Z
* @return the chunk at the specified position, null if not loaded * @return the chunk at the specified position, null if not loaded
*/ */
@Nullable
public abstract Chunk getChunk(int chunkX, int chunkZ); public abstract Chunk getChunk(int chunkX, int chunkZ);
/** /**
@ -186,14 +189,14 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* @param chunk the {@link Chunk} to save * @param chunk the {@link Chunk} to save
* @param callback optional callback called when the {@link Chunk} is done saving * @param callback optional callback called when the {@link Chunk} is done saving
*/ */
public abstract void saveChunkToStorage(Chunk chunk, Runnable callback); public abstract void saveChunkToStorage(Chunk chunk, @Nullable Runnable callback);
/** /**
* Saves multiple chunks to permanent storage. * Saves multiple chunks to permanent storage.
* *
* @param callback optional callback called when the chunks are done saving * @param callback optional callback called when the chunks are done saving
*/ */
public abstract void saveChunksToStorage(Runnable callback); public abstract void saveChunksToStorage(@Nullable Runnable callback);
/** /**
* Creates a new {@link BlockBatch} linked to this instance. * Creates a new {@link BlockBatch} linked to this instance.
@ -256,7 +259,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* @param chunkZ the chunk X * @param chunkZ the chunk X
* @param callback the optional callback executed once the {@link Chunk} has been retrieved * @param callback the optional callback executed once the {@link Chunk} has been retrieved
*/ */
protected abstract void retrieveChunk(int chunkX, int chunkZ, ChunkCallback callback); protected abstract void retrieveChunk(int chunkX, int chunkZ, @Nullable ChunkCallback callback);
/** /**
* Called to generated a new {@link Chunk} from scratch. * Called to generated a new {@link Chunk} from scratch.
@ -267,7 +270,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* @param chunkZ the chunk Z * @param chunkZ the chunk Z
* @param callback the optional callback executed with the newly created {@link Chunk} * @param callback the optional callback executed with the newly created {@link Chunk}
*/ */
protected abstract void createChunk(int chunkX, int chunkZ, ChunkCallback callback); protected abstract void createChunk(int chunkX, int chunkZ, @Nullable ChunkCallback callback);
/** /**
* When set to true, chunks will load automatically when requested. * When set to true, chunks will load automatically when requested.
@ -543,7 +546,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* @param position the chunk position * @param position the chunk position
* @param callback the optional callback to run when the chunk is loaded * @param callback the optional callback to run when the chunk is loaded
*/ */
public void loadChunk(Position position, ChunkCallback callback) { public void loadChunk(Position position, @Nullable ChunkCallback callback) {
final int chunkX = ChunkUtils.getChunkCoordinate((int) position.getX()); final int chunkX = ChunkUtils.getChunkCoordinate((int) position.getX());
final int chunkZ = ChunkUtils.getChunkCoordinate((int) position.getZ()); final int chunkZ = ChunkUtils.getChunkCoordinate((int) position.getZ());
loadChunk(chunkX, chunkZ, callback); loadChunk(chunkX, chunkZ, callback);
@ -556,7 +559,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* @param position the chunk position * @param position the chunk position
* @param callback the optional callback executed when the chunk is loaded (or with a null chunk if not) * @param callback the optional callback executed when the chunk is loaded (or with a null chunk if not)
*/ */
public void loadOptionalChunk(Position position, ChunkCallback callback) { public void loadOptionalChunk(Position position, @Nullable ChunkCallback callback) {
final int chunkX = ChunkUtils.getChunkCoordinate((int) position.getX()); final int chunkX = ChunkUtils.getChunkCoordinate((int) position.getX());
final int chunkZ = ChunkUtils.getChunkCoordinate((int) position.getZ()); final int chunkZ = ChunkUtils.getChunkCoordinate((int) position.getZ());
loadOptionalChunk(chunkX, chunkZ, callback); loadOptionalChunk(chunkX, chunkZ, callback);
@ -606,7 +609,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* @param blockPosition the block position * @param blockPosition the block position
* @return the block state id at the position * @return the block state id at the position
*/ */
public short getBlockStateId(BlockPosition blockPosition) { public short getBlockStateId(@NotNull BlockPosition blockPosition) {
return getBlockStateId(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ()); return getBlockStateId(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ());
} }
@ -618,6 +621,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* @param z the Z position * @param z the Z position
* @return the custom block object at the position, null if not any * @return the custom block object at the position, null if not any
*/ */
@Nullable
public CustomBlock getCustomBlock(int x, int y, int z) { public CustomBlock getCustomBlock(int x, int y, int z) {
final Chunk chunk = getChunkAt(x, z); final Chunk chunk = getChunkAt(x, z);
Check.notNull(chunk, "The chunk at " + x + ":" + z + " is not loaded"); Check.notNull(chunk, "The chunk at " + x + ":" + z + " is not loaded");
@ -630,7 +634,8 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* @param blockPosition the block position * @param blockPosition the block position
* @return the custom block object at the position, null if not any * @return the custom block object at the position, null if not any
*/ */
public CustomBlock getCustomBlock(BlockPosition blockPosition) { @Nullable
public CustomBlock getCustomBlock(@NotNull BlockPosition blockPosition) {
return getCustomBlock(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ()); return getCustomBlock(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ());
} }
@ -642,7 +647,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* @param actionParam * @param actionParam
* @see <a href="https://wiki.vg/Protocol#Block_Action">BlockActionPacket</a> for the action id &amp; param * @see <a href="https://wiki.vg/Protocol#Block_Action">BlockActionPacket</a> for the action id &amp; param
*/ */
public void sendBlockAction(BlockPosition blockPosition, byte actionId, byte actionParam) { public void sendBlockAction(@NotNull BlockPosition blockPosition, byte actionId, byte actionParam) {
final short blockStateId = getBlockStateId(blockPosition); final short blockStateId = getBlockStateId(blockPosition);
final Block block = Block.fromStateId(blockStateId); final Block block = Block.fromStateId(blockStateId);
@ -677,7 +682,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* @param blockPosition the block position * @param blockPosition the block position
* @return the block data at the position, null if not any * @return the block data at the position, null if not any
*/ */
public Data getBlockData(BlockPosition blockPosition) { public Data getBlockData(@NotNull BlockPosition blockPosition) {
return getBlockData(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ()); return getBlockData(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ());
} }
@ -689,7 +694,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* @param z the Z position * @param z the Z position
* @param data the data to be set, can be null * @param data the data to be set, can be null
*/ */
public void setBlockData(int x, int y, int z, Data data) { public void setBlockData(int x, int y, int z, @Nullable Data data) {
final Chunk chunk = getChunkAt(x, z); final Chunk chunk = getChunkAt(x, z);
Check.notNull(chunk, "The chunk at " + x + ":" + z + " is not loaded"); Check.notNull(chunk, "The chunk at " + x + ":" + z + " is not loaded");
synchronized (chunk) { synchronized (chunk) {
@ -703,7 +708,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* @param blockPosition the block position * @param blockPosition the block position
* @param data the data to be set, can be null * @param data the data to be set, can be null
*/ */
public void setBlockData(BlockPosition blockPosition, Data data) { public void setBlockData(@NotNull BlockPosition blockPosition, Data data) {
setBlockData(blockPosition.getX(), (byte) blockPosition.getY(), blockPosition.getZ(), data); setBlockData(blockPosition.getX(), (byte) blockPosition.getY(), blockPosition.getZ(), data);
} }
@ -714,6 +719,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* @param z the Z position * @param z the Z position
* @return the chunk at the given position, null if not loaded * @return the chunk at the given position, null if not loaded
*/ */
@Nullable
public Chunk getChunkAt(float x, float z) { public Chunk getChunkAt(float x, float z) {
final int chunkX = ChunkUtils.getChunkCoordinate((int) x); final int chunkX = ChunkUtils.getChunkCoordinate((int) x);
final int chunkZ = ChunkUtils.getChunkCoordinate((int) z); final int chunkZ = ChunkUtils.getChunkCoordinate((int) z);
@ -737,7 +743,8 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* @param blockPosition the chunk position * @param blockPosition the chunk position
* @return the chunk at the given position, null if not loaded * @return the chunk at the given position, null if not loaded
*/ */
public Chunk getChunkAt(BlockPosition blockPosition) { @Nullable
public Chunk getChunkAt(@NotNull BlockPosition blockPosition) {
return getChunkAt(blockPosition.getX(), blockPosition.getZ()); return getChunkAt(blockPosition.getX(), blockPosition.getZ());
} }
@ -747,7 +754,8 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* @param position the chunk position * @param position the chunk position
* @return the chunk at the given position, null if not loaded * @return the chunk at the given position, null if not loaded
*/ */
public Chunk getChunkAt(Position position) { @Nullable
public Chunk getChunkAt(@NotNull Position position) {
return getChunkAt(position.getX(), position.getZ()); return getChunkAt(position.getX(), position.getZ());
} }
@ -756,7 +764,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* *
* @param chunk the chunk to save * @param chunk the chunk to save
*/ */
public void saveChunkToStorage(Chunk chunk) { public void saveChunkToStorage(@NotNull Chunk chunk) {
saveChunkToStorage(chunk, null); saveChunkToStorage(chunk, null);
} }
@ -772,6 +780,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* *
* @return the instance unique id * @return the instance unique id
*/ */
@NotNull
public UUID getUniqueId() { public UUID getUniqueId() {
return uniqueId; return uniqueId;
} }
@ -782,7 +791,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
} }
@Override @Override
public void setData(Data data) { public void setData(@Nullable Data data) {
this.data = data; this.data = data;
} }
@ -801,7 +810,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* *
* @param entity the entity to add * @param entity the entity to add
*/ */
public void addEntity(Entity entity) { public void addEntity(@NotNull Entity entity) {
final Instance lastInstance = entity.getInstance(); final Instance lastInstance = entity.getInstance();
if (lastInstance != null && lastInstance != this) { if (lastInstance != null && lastInstance != this) {
lastInstance.removeEntity(entity); // If entity is in another instance, remove it from there and add it to this lastInstance.removeEntity(entity); // If entity is in another instance, remove it from there and add it to this
@ -844,7 +853,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* *
* @param entity the entity to remove * @param entity the entity to remove
*/ */
public void removeEntity(Entity entity) { public void removeEntity(@NotNull Entity entity) {
final Instance entityInstance = entity.getInstance(); final Instance entityInstance = entity.getInstance();
if (entityInstance != this) if (entityInstance != this)
return; return;
@ -868,7 +877,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* @param entity the entity to add * @param entity the entity to add
* @param chunk the chunk where the entity will be added * @param chunk the chunk where the entity will be added
*/ */
public void addEntityToChunk(Entity entity, Chunk chunk) { public void addEntityToChunk(@NotNull Entity entity, @NotNull Chunk chunk) {
Check.notNull(chunk, Check.notNull(chunk,
"The chunk " + chunk + " is not loaded, you can make it automatic by using Instance#enableAutoChunkLoad(true)"); "The chunk " + chunk + " is not loaded, you can make it automatic by using Instance#enableAutoChunkLoad(true)");
Check.argCondition(!chunk.isLoaded(), "Chunk " + chunk + " has been unloaded previously"); Check.argCondition(!chunk.isLoaded(), "Chunk " + chunk + " has been unloaded previously");
@ -899,7 +908,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* @param entity the entity to remove * @param entity the entity to remove
* @param chunk the chunk where the entity will be removed * @param chunk the chunk where the entity will be removed
*/ */
public void removeEntityFromChunk(Entity entity, Chunk chunk) { public void removeEntityFromChunk(@NotNull Entity entity, @NotNull Chunk chunk) {
synchronized (chunkEntities) { synchronized (chunkEntities) {
if (chunk != null) { if (chunk != null) {
final long chunkIndex = ChunkUtils.getChunkIndex(chunk.getChunkX(), chunk.getChunkZ()); final long chunkIndex = ChunkUtils.getChunkIndex(chunk.getChunkX(), chunk.getChunkZ());
@ -925,13 +934,14 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
} }
} }
@NotNull
private Set<Entity> getEntitiesInChunk(long index) { private Set<Entity> getEntitiesInChunk(long index) {
return chunkEntities.computeIfAbsent(index, i -> new CopyOnWriteArraySet<>()); return chunkEntities.computeIfAbsent(index, i -> new CopyOnWriteArraySet<>());
} }
/** /**
* Schedules a block update at a given {@link BlockPosition}. * Schedules a block update at a given {@link BlockPosition}.
* Does nothing if no {@link CustomBlock} is present at 'position'. * Does nothing if no {@link CustomBlock} is present at {@code position}.
* <p> * <p>
* Cancelled if the block changes between this call and the actual update. * Cancelled if the block changes between this call and the actual update.
* *
@ -939,7 +949,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* @param unit in what unit is the time expressed * @param unit in what unit is the time expressed
* @param position the location of the block to update * @param position the location of the block to update
*/ */
public abstract void scheduleUpdate(int time, TimeUnit unit, BlockPosition position); public abstract void scheduleUpdate(int time, @NotNull TimeUnit unit, @NotNull BlockPosition position);
/** /**
* Performs a single tick in the instance, including scheduled tasks from {@link #scheduleNextTick(Consumer)}. * Performs a single tick in the instance, including scheduled tasks from {@link #scheduleNextTick(Consumer)}.
@ -999,7 +1009,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* @param additionalData data to pass to the explosion supplier * @param additionalData data to pass to the explosion supplier
* @throws IllegalStateException If no {@link ExplosionSupplier} was supplied * @throws IllegalStateException If no {@link ExplosionSupplier} was supplied
*/ */
public void explode(float centerX, float centerY, float centerZ, float strength, Data additionalData) { public void explode(float centerX, float centerY, float centerZ, float strength, @Nullable Data additionalData) {
final ExplosionSupplier explosionSupplier = getExplosionSupplier(); final ExplosionSupplier explosionSupplier = getExplosionSupplier();
Check.stateCondition(explosionSupplier == null, "Tried to create an explosion with no explosion supplier"); Check.stateCondition(explosionSupplier == null, "Tried to create an explosion with no explosion supplier");
final Explosion explosion = explosionSupplier.createExplosion(centerX, centerY, centerZ, strength, additionalData); final Explosion explosion = explosionSupplier.createExplosion(centerX, centerY, centerZ, strength, additionalData);
@ -1011,6 +1021,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* *
* @return the instance explosion supplier, null if none was provided * @return the instance explosion supplier, null if none was provided
*/ */
@Nullable
public ExplosionSupplier getExplosionSupplier() { public ExplosionSupplier getExplosionSupplier() {
return explosionSupplier; return explosionSupplier;
} }
@ -1020,7 +1031,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* *
* @param supplier the explosion supplier * @param supplier the explosion supplier
*/ */
public void setExplosionSupplier(ExplosionSupplier supplier) { public void setExplosionSupplier(@Nullable ExplosionSupplier supplier) {
this.explosionSupplier = supplier; this.explosionSupplier = supplier;
} }
@ -1031,6 +1042,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* *
* @return the instance space * @return the instance space
*/ */
@NotNull
public PFInstanceSpace getInstanceSpace() { public PFInstanceSpace getInstanceSpace() {
return instanceSpace; return instanceSpace;
} }

View File

@ -29,6 +29,8 @@ import net.minestom.server.utils.time.TimeUnit;
import net.minestom.server.utils.validate.Check; import net.minestom.server.utils.validate.Check;
import net.minestom.server.world.DimensionType; import net.minestom.server.world.DimensionType;
import net.minestom.server.world.biomes.Biome; import net.minestom.server.world.biomes.Biome;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -393,7 +395,7 @@ public class InstanceContainer extends Instance {
} }
@Override @Override
public void loadChunk(int chunkX, int chunkZ, ChunkCallback callback) { public void loadChunk(int chunkX, int chunkZ, @Nullable ChunkCallback callback) {
final Chunk chunk = getChunk(chunkX, chunkZ); final Chunk chunk = getChunk(chunkX, chunkZ);
if (chunk != null) { if (chunk != null) {
// Chunk already loaded // Chunk already loaded
@ -405,7 +407,7 @@ public class InstanceContainer extends Instance {
} }
@Override @Override
public void loadOptionalChunk(int chunkX, int chunkZ, ChunkCallback callback) { public void loadOptionalChunk(int chunkX, int chunkZ, @Nullable ChunkCallback callback) {
final Chunk chunk = getChunk(chunkX, chunkZ); final Chunk chunk = getChunk(chunkX, chunkZ);
if (chunk != null) { if (chunk != null) {
// Chunk already loaded // Chunk already loaded
@ -422,7 +424,7 @@ public class InstanceContainer extends Instance {
} }
@Override @Override
public void unloadChunk(Chunk chunk) { public void unloadChunk(@NotNull Chunk chunk) {
// Already unloaded chunk // Already unloaded chunk
if (!ChunkUtils.isLoaded(chunk)) { if (!ChunkUtils.isLoaded(chunk)) {
return; return;
@ -445,9 +447,9 @@ public class InstanceContainer extends Instance {
* <p> * <p>
* WARNING: {@link #getData()} needs to be a {@link SerializableData} in order to be saved. * WARNING: {@link #getData()} needs to be a {@link SerializableData} in order to be saved.
* *
* @param callback the callback once the saving is done. Can be null. * @param callback the optional callback once the saving is done
*/ */
public void saveInstance(Runnable callback) { public void saveInstance(@Nullable Runnable callback) {
Check.notNull(getStorageLocation(), "You cannot save the instance if no StorageLocation has been defined"); Check.notNull(getStorageLocation(), "You cannot save the instance if no StorageLocation has been defined");
this.storageLocation.set(UUID_KEY, getUniqueId(), UUID.class); this.storageLocation.set(UUID_KEY, getUniqueId(), UUID.class);
@ -493,7 +495,7 @@ public class InstanceContainer extends Instance {
} }
@Override @Override
protected void retrieveChunk(int chunkX, int chunkZ, ChunkCallback callback) { protected void retrieveChunk(int chunkX, int chunkZ, @Nullable ChunkCallback callback) {
final boolean loaded = chunkLoader.loadChunk(this, chunkX, chunkZ, chunk -> { final boolean loaded = chunkLoader.loadChunk(this, chunkX, chunkZ, chunk -> {
cacheChunk(chunk); cacheChunk(chunk);
UPDATE_MANAGER.signalChunkLoad(this, chunkX, chunkZ); UPDATE_MANAGER.signalChunkLoad(this, chunkX, chunkZ);
@ -511,7 +513,7 @@ public class InstanceContainer extends Instance {
} }
@Override @Override
protected void createChunk(int chunkX, int chunkZ, ChunkCallback callback) { protected void createChunk(int chunkX, int chunkZ, @Nullable ChunkCallback callback) {
Biome[] biomes = new Biome[Chunk.BIOME_COUNT]; Biome[] biomes = new Biome[Chunk.BIOME_COUNT];
if (chunkGenerator == null) { if (chunkGenerator == null) {
Arrays.fill(biomes, MinecraftServer.getBiomeManager().getById(0)); Arrays.fill(biomes, MinecraftServer.getBiomeManager().getById(0));
@ -566,7 +568,7 @@ public class InstanceContainer extends Instance {
* @param chunkSupplier the new {@link ChunkSupplier} of this instance, chunks need to be non-null * @param chunkSupplier the new {@link ChunkSupplier} of this instance, chunks need to be non-null
* @throws NullPointerException if {@code chunkSupplier} is null * @throws NullPointerException if {@code chunkSupplier} is null
*/ */
public void setChunkSupplier(ChunkSupplier chunkSupplier) { public void setChunkSupplier(@NotNull ChunkSupplier chunkSupplier) {
Check.notNull(chunkSupplier, "The chunk supplier cannot be null, you can use a StaticChunk for a lightweight implementation"); Check.notNull(chunkSupplier, "The chunk supplier cannot be null, you can use a StaticChunk for a lightweight implementation");
this.chunkSupplier = chunkSupplier; this.chunkSupplier = chunkSupplier;
} }
@ -676,7 +678,7 @@ public class InstanceContainer extends Instance {
} }
@Override @Override
public void scheduleUpdate(int time, TimeUnit unit, BlockPosition position) { public void scheduleUpdate(int time, @NotNull TimeUnit unit, @NotNull BlockPosition position) {
final CustomBlock toUpdate = getCustomBlock(position); final CustomBlock toUpdate = getCustomBlock(position);
if (toUpdate == null) { if (toUpdate == null) {
return; return;

View File

@ -5,6 +5,7 @@ import net.minestom.server.utils.binary.BinaryReader;
import net.minestom.server.utils.callback.OptionalCallback; import net.minestom.server.utils.callback.OptionalCallback;
import net.minestom.server.utils.chunk.ChunkCallback; import net.minestom.server.utils.chunk.ChunkCallback;
import net.minestom.server.utils.chunk.ChunkSupplier; import net.minestom.server.utils.chunk.ChunkSupplier;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -36,7 +37,7 @@ public class MinestomBasicChunkLoader implements IChunkLoader {
} }
@Override @Override
public void saveChunk(Chunk chunk, Runnable callback) { public void saveChunk(@NotNull Chunk chunk, Runnable callback) {
final StorageLocation storageLocation = instanceContainer.getStorageLocation(); final StorageLocation storageLocation = instanceContainer.getStorageLocation();
if (storageLocation == null) { if (storageLocation == null) {
callback.run(); callback.run();
@ -64,7 +65,7 @@ public class MinestomBasicChunkLoader implements IChunkLoader {
} }
@Override @Override
public boolean loadChunk(Instance instance, int chunkX, int chunkZ, ChunkCallback callback) { public boolean loadChunk(@NotNull Instance instance, int chunkX, int chunkZ, ChunkCallback callback) {
final StorageLocation storageLocation = instanceContainer.getStorageLocation(); final StorageLocation storageLocation = instanceContainer.getStorageLocation();
final byte[] bytes = storageLocation == null ? null : storageLocation.get(getChunkKey(chunkX, chunkZ)); final byte[] bytes = storageLocation == null ? null : storageLocation.get(getChunkKey(chunkX, chunkZ));

View File

@ -9,6 +9,8 @@ import net.minestom.server.utils.BlockPosition;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import net.minestom.server.utils.chunk.ChunkCallback; import net.minestom.server.utils.chunk.ChunkCallback;
import net.minestom.server.utils.time.TimeUnit; import net.minestom.server.utils.time.TimeUnit;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection; import java.util.Collection;
import java.util.UUID; import java.util.UUID;
@ -37,17 +39,17 @@ public class SharedInstance extends Instance {
} }
@Override @Override
public void loadChunk(int chunkX, int chunkZ, ChunkCallback callback) { public void loadChunk(int chunkX, int chunkZ, @Nullable ChunkCallback callback) {
this.instanceContainer.loadChunk(chunkX, chunkZ, callback); this.instanceContainer.loadChunk(chunkX, chunkZ, callback);
} }
@Override @Override
public void loadOptionalChunk(int chunkX, int chunkZ, ChunkCallback callback) { public void loadOptionalChunk(int chunkX, int chunkZ, @Nullable ChunkCallback callback) {
this.instanceContainer.loadOptionalChunk(chunkX, chunkZ, callback); this.instanceContainer.loadOptionalChunk(chunkX, chunkZ, callback);
} }
@Override @Override
public void unloadChunk(Chunk chunk) { public void unloadChunk(@NotNull Chunk chunk) {
instanceContainer.unloadChunk(chunk); instanceContainer.unloadChunk(chunk);
} }
@ -57,12 +59,12 @@ public class SharedInstance extends Instance {
} }
@Override @Override
public void saveChunkToStorage(Chunk chunk, Runnable callback) { public void saveChunkToStorage(Chunk chunk, @Nullable Runnable callback) {
this.instanceContainer.saveChunkToStorage(chunk, callback); this.instanceContainer.saveChunkToStorage(chunk, callback);
} }
@Override @Override
public void saveChunksToStorage(Runnable callback) { public void saveChunksToStorage(@Nullable Runnable callback) {
instanceContainer.saveChunksToStorage(callback); instanceContainer.saveChunksToStorage(callback);
} }
@ -102,7 +104,7 @@ public class SharedInstance extends Instance {
} }
@Override @Override
public void retrieveChunk(int chunkX, int chunkZ, ChunkCallback callback) { public void retrieveChunk(int chunkX, int chunkZ, @Nullable ChunkCallback callback) {
this.instanceContainer.retrieveChunk(chunkX, chunkZ, callback); this.instanceContainer.retrieveChunk(chunkX, chunkZ, callback);
} }
@ -142,12 +144,12 @@ public class SharedInstance extends Instance {
} }
@Override @Override
public void scheduleUpdate(int time, TimeUnit unit, BlockPosition position) { public void scheduleUpdate(int time, @NotNull TimeUnit unit, @NotNull BlockPosition position) {
this.instanceContainer.scheduleUpdate(time, unit, position); this.instanceContainer.scheduleUpdate(time, unit, position);
} }
/** /**
* Gets the {@link InstanceContainer} from where this instance takes its {@link Chunk} from. * Gets the {@link InstanceContainer} from where this instance takes its chunks from.
* *
* @return the associated {@link InstanceContainer} * @return the associated {@link InstanceContainer}
*/ */

View File

@ -5,9 +5,12 @@ import net.minestom.server.data.Data;
import net.minestom.server.instance.block.BlockProvider; import net.minestom.server.instance.block.BlockProvider;
import net.minestom.server.network.packet.server.play.ChunkDataPacket; import net.minestom.server.network.packet.server.play.ChunkDataPacket;
import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryReader;
import net.minestom.server.utils.callback.OptionalCallback;
import net.minestom.server.utils.chunk.ChunkCallback; import net.minestom.server.utils.chunk.ChunkCallback;
import net.minestom.server.utils.chunk.ChunkUtils; import net.minestom.server.utils.chunk.ChunkUtils;
import net.minestom.server.world.biomes.Biome; import net.minestom.server.world.biomes.Biome;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@ -36,7 +39,7 @@ public class StaticChunk extends Chunk {
} }
@Override @Override
public void tick(long time, Instance instance) { public void tick(long time, @NotNull Instance instance) {
//noop //noop
} }
@ -71,6 +74,7 @@ public class StaticChunk extends Chunk {
//noop //noop
} }
@NotNull
@Override @Override
public Set<Integer> getBlockEntities() { public Set<Integer> getBlockEntities() {
return new HashSet<>(); return new HashSet<>();
@ -82,10 +86,11 @@ public class StaticChunk extends Chunk {
} }
@Override @Override
public void readChunk(BinaryReader reader, ChunkCallback callback) { public void readChunk(@NotNull BinaryReader reader, @Nullable ChunkCallback callback) {
callback.accept(this); OptionalCallback.execute(callback, this);
} }
@NotNull
@Override @Override
protected ChunkDataPacket createFreshPacket() { protected ChunkDataPacket createFreshPacket() {
ChunkDataPacket fullDataPacket = new ChunkDataPacket(); ChunkDataPacket fullDataPacket = new ChunkDataPacket();

View File

@ -6,6 +6,7 @@ import net.minestom.server.instance.*;
import net.minestom.server.instance.block.CustomBlock; import net.minestom.server.instance.block.CustomBlock;
import net.minestom.server.utils.block.CustomBlockUtils; import net.minestom.server.utils.block.CustomBlockUtils;
import net.minestom.server.utils.chunk.ChunkCallback; import net.minestom.server.utils.chunk.ChunkCallback;
import org.jetbrains.annotations.Nullable;
import java.util.List; import java.util.List;
@ -57,7 +58,7 @@ public class ChunkBatch implements InstanceBatch {
} }
} }
public void flushChunkGenerator(ChunkGenerator chunkGenerator, ChunkCallback callback) { public void flushChunkGenerator(ChunkGenerator chunkGenerator, @Nullable ChunkCallback callback) {
BLOCK_BATCH_POOL.execute(() -> { BLOCK_BATCH_POOL.execute(() -> {
final List<ChunkPopulator> populators = chunkGenerator.getPopulators(); final List<ChunkPopulator> populators = chunkGenerator.getPopulators();
final boolean hasPopulator = populators != null && !populators.isEmpty(); final boolean hasPopulator = populators != null && !populators.isEmpty();
@ -84,7 +85,7 @@ public class ChunkBatch implements InstanceBatch {
* *
* @param callback the callback to execute once the blocks are placed * @param callback the callback to execute once the blocks are placed
*/ */
public void flush(ChunkCallback callback) { public void flush(@Nullable ChunkCallback callback) {
BLOCK_BATCH_POOL.execute(() -> singleThreadFlush(callback, true)); BLOCK_BATCH_POOL.execute(() -> singleThreadFlush(callback, true));
} }
@ -95,7 +96,7 @@ public class ChunkBatch implements InstanceBatch {
* *
* @param callback the callback to execute once the blocks are placed * @param callback the callback to execute once the blocks are placed
*/ */
public void unsafeFlush(ChunkCallback callback) { public void unsafeFlush(@Nullable ChunkCallback callback) {
BLOCK_BATCH_POOL.execute(() -> singleThreadFlush(callback, false)); BLOCK_BATCH_POOL.execute(() -> singleThreadFlush(callback, false));
} }
@ -114,7 +115,7 @@ public class ChunkBatch implements InstanceBatch {
* @param callback the callback to execute once the blocks are placed * @param callback the callback to execute once the blocks are placed
* @param safeCallback true to run the callback in the instance update thread, otherwise run in the current one * @param safeCallback true to run the callback in the instance update thread, otherwise run in the current one
*/ */
private void singleThreadFlush(ChunkCallback callback, boolean safeCallback) { private void singleThreadFlush(@Nullable ChunkCallback callback, boolean safeCallback) {
synchronized (chunk) { synchronized (chunk) {
if (!chunk.isLoaded()) if (!chunk.isLoaded())
return; return;
@ -145,7 +146,7 @@ public class ChunkBatch implements InstanceBatch {
private final short customBlockId; private final short customBlockId;
private final Data data; private final Data data;
private BlockData(int x, int y, int z, short blockStateId, short customBlockId, Data data) { private BlockData(int x, int y, int z, short blockStateId, short customBlockId, @Nullable Data data) {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;

View File

@ -19,6 +19,7 @@ import net.minestom.server.utils.MathUtils;
import net.minestom.server.utils.inventory.PlayerInventoryUtils; import net.minestom.server.utils.inventory.PlayerInventoryUtils;
import net.minestom.server.utils.item.ItemStackUtils; import net.minestom.server.utils.item.ItemStackUtils;
import net.minestom.server.utils.validate.Check; import net.minestom.server.utils.validate.Check;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -238,20 +239,21 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
sendSlotRefresh(slot, getItemStack(slot)); sendSlotRefresh(slot, getItemStack(slot));
} }
@NotNull
@Override @Override
public Set<Player> getViewers() { public Set<Player> getViewers() {
return Collections.unmodifiableSet(viewers); return Collections.unmodifiableSet(viewers);
} }
@Override @Override
public boolean addViewer(Player player) { public boolean addViewer(@NotNull Player player) {
final boolean result = this.viewers.add(player); final boolean result = this.viewers.add(player);
update(player); update(player);
return result; return result;
} }
@Override @Override
public boolean removeViewer(Player player) { public boolean removeViewer(@NotNull Player player) {
final boolean result = this.viewers.remove(player); final boolean result = this.viewers.remove(player);
this.cursorPlayersItem.remove(player); this.cursorPlayersItem.remove(player);
this.clickProcessor.clearCache(player); this.clickProcessor.clearCache(player);

View File

@ -1,5 +1,6 @@
package net.minestom.server.item.metadata; package net.minestom.server.item.metadata;
import org.jetbrains.annotations.NotNull;
import org.jglrxavpok.hephaistos.nbt.NBTCompound; import org.jglrxavpok.hephaistos.nbt.NBTCompound;
public class CompassMeta implements ItemMeta { public class CompassMeta implements ItemMeta {
@ -54,7 +55,7 @@ public class CompassMeta implements ItemMeta {
} }
@Override @Override
public boolean isSimilar(ItemMeta itemMeta) { public boolean isSimilar(@NotNull ItemMeta itemMeta) {
if (!(itemMeta instanceof CompassMeta)) if (!(itemMeta instanceof CompassMeta))
return false; return false;
CompassMeta compassMeta = (CompassMeta) itemMeta; CompassMeta compassMeta = (CompassMeta) itemMeta;
@ -64,7 +65,7 @@ public class CompassMeta implements ItemMeta {
} }
@Override @Override
public void read(NBTCompound compound) { public void read(@NotNull NBTCompound compound) {
if (compound.containsKey("LodestoneTracked")) { if (compound.containsKey("LodestoneTracked")) {
this.lodestoneTracked = compound.getByte("LodestoneTracked") == 1; this.lodestoneTracked = compound.getByte("LodestoneTracked") == 1;
// TODO get boolean // TODO get boolean
@ -81,7 +82,7 @@ public class CompassMeta implements ItemMeta {
} }
@Override @Override
public void write(NBTCompound compound) { public void write(@NotNull NBTCompound compound) {
compound.setByte("LodestoneTracked", (byte) (lodestoneTracked ? 1 : 0)); compound.setByte("LodestoneTracked", (byte) (lodestoneTracked ? 1 : 0));
if(lodestoneDimension != null) { if(lodestoneDimension != null) {
compound.setString("LodestoneDimension", lodestoneDimension); compound.setString("LodestoneDimension", lodestoneDimension);
@ -96,6 +97,7 @@ public class CompassMeta implements ItemMeta {
} }
} }
@NotNull
@Override @Override
public ItemMeta clone() { public ItemMeta clone() {
CompassMeta compassMeta = new CompassMeta(); CompassMeta compassMeta = new CompassMeta();

View File

@ -6,6 +6,7 @@ import net.minestom.server.registry.Registries;
import net.minestom.server.utils.NBTUtils; import net.minestom.server.utils.NBTUtils;
import net.minestom.server.utils.item.ItemStackUtils; import net.minestom.server.utils.item.ItemStackUtils;
import net.minestom.server.utils.validate.Check; import net.minestom.server.utils.validate.Check;
import org.jetbrains.annotations.NotNull;
import org.jglrxavpok.hephaistos.nbt.NBTCompound; import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import org.jglrxavpok.hephaistos.nbt.NBTList; import org.jglrxavpok.hephaistos.nbt.NBTList;
import org.jglrxavpok.hephaistos.nbt.NBTTypes; import org.jglrxavpok.hephaistos.nbt.NBTTypes;
@ -106,7 +107,7 @@ public class CrossbowMeta implements ItemMeta {
} }
@Override @Override
public boolean isSimilar(ItemMeta itemMeta) { public boolean isSimilar(@NotNull ItemMeta itemMeta) {
if (!(itemMeta instanceof CrossbowMeta)) if (!(itemMeta instanceof CrossbowMeta))
return false; return false;
@ -125,7 +126,7 @@ public class CrossbowMeta implements ItemMeta {
} }
@Override @Override
public void read(NBTCompound compound) { public void read(@NotNull NBTCompound compound) {
if (compound.containsKey("ChargedProjectiles")) { if (compound.containsKey("ChargedProjectiles")) {
final NBTList<NBTCompound> projectilesList = compound.getList("ChargedProjectiles"); final NBTList<NBTCompound> projectilesList = compound.getList("ChargedProjectiles");
int index = 0; int index = 0;
@ -158,7 +159,7 @@ public class CrossbowMeta implements ItemMeta {
} }
@Override @Override
public void write(NBTCompound compound) { public void write(@NotNull NBTCompound compound) {
if (projectile1 != null || projectile2 != null || projectile3 != null) { if (projectile1 != null || projectile2 != null || projectile3 != null) {
NBTList<NBTCompound> chargedProjectiles = new NBTList<>(NBTTypes.TAG_Compound); NBTList<NBTCompound> chargedProjectiles = new NBTList<>(NBTTypes.TAG_Compound);
if (projectile1 != null) { if (projectile1 != null) {
@ -178,6 +179,7 @@ public class CrossbowMeta implements ItemMeta {
} }
} }
@NotNull
@Override @Override
public ItemMeta clone() { public ItemMeta clone() {
CrossbowMeta crossbowMeta = new CrossbowMeta(); CrossbowMeta crossbowMeta = new CrossbowMeta();

View File

@ -2,6 +2,7 @@ package net.minestom.server.item.metadata;
import net.minestom.server.item.Enchantment; import net.minestom.server.item.Enchantment;
import net.minestom.server.utils.NBTUtils; import net.minestom.server.utils.NBTUtils;
import org.jetbrains.annotations.NotNull;
import org.jglrxavpok.hephaistos.nbt.NBTCompound; import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import java.util.Collections; import java.util.Collections;
@ -18,6 +19,7 @@ public class EnchantedBookMeta implements ItemMeta {
* *
* @return an unmodifiable map containing the item stored enchantments * @return an unmodifiable map containing the item stored enchantments
*/ */
@NotNull
public Map<Enchantment, Short> getStoredEnchantmentMap() { public Map<Enchantment, Short> getStoredEnchantmentMap() {
return Collections.unmodifiableMap(storedEnchantmentMap); return Collections.unmodifiableMap(storedEnchantmentMap);
} }
@ -28,7 +30,7 @@ public class EnchantedBookMeta implements ItemMeta {
* @param enchantment the enchantment type * @param enchantment the enchantment type
* @param level the enchantment level * @param level the enchantment level
*/ */
public void setStoredEnchantment(Enchantment enchantment, short level) { public void setStoredEnchantment(@NotNull Enchantment enchantment, short level) {
if (level < 1) { if (level < 1) {
removeStoredEnchantment(enchantment); removeStoredEnchantment(enchantment);
return; return;
@ -42,7 +44,7 @@ public class EnchantedBookMeta implements ItemMeta {
* *
* @param enchantment the enchantment type * @param enchantment the enchantment type
*/ */
public void removeStoredEnchantment(Enchantment enchantment) { public void removeStoredEnchantment(@NotNull Enchantment enchantment) {
this.storedEnchantmentMap.remove(enchantment); this.storedEnchantmentMap.remove(enchantment);
} }
@ -52,7 +54,7 @@ public class EnchantedBookMeta implements ItemMeta {
* @param enchantment the enchantment type * @param enchantment the enchantment type
* @return the stored enchantment level, 0 if not present * @return the stored enchantment level, 0 if not present
*/ */
public int getStoredEnchantmentLevel(Enchantment enchantment) { public int getStoredEnchantmentLevel(@NotNull Enchantment enchantment) {
return this.storedEnchantmentMap.getOrDefault(enchantment, (short) 0); return this.storedEnchantmentMap.getOrDefault(enchantment, (short) 0);
} }
@ -62,25 +64,26 @@ public class EnchantedBookMeta implements ItemMeta {
} }
@Override @Override
public boolean isSimilar(ItemMeta itemMeta) { public boolean isSimilar(@NotNull ItemMeta itemMeta) {
return itemMeta instanceof EnchantedBookMeta && return itemMeta instanceof EnchantedBookMeta &&
((EnchantedBookMeta) itemMeta).storedEnchantmentMap.equals(storedEnchantmentMap); ((EnchantedBookMeta) itemMeta).storedEnchantmentMap.equals(storedEnchantmentMap);
} }
@Override @Override
public void read(NBTCompound compound) { public void read(@NotNull NBTCompound compound) {
if (compound.containsKey("StoredEnchantments")) { if (compound.containsKey("StoredEnchantments")) {
NBTUtils.loadEnchantments(compound.getList("StoredEnchantments"), this::setStoredEnchantment); NBTUtils.loadEnchantments(compound.getList("StoredEnchantments"), this::setStoredEnchantment);
} }
} }
@Override @Override
public void write(NBTCompound compound) { public void write(@NotNull NBTCompound compound) {
if (!storedEnchantmentMap.isEmpty()) { if (!storedEnchantmentMap.isEmpty()) {
NBTUtils.writeEnchant(compound, "StoredEnchantments", storedEnchantmentMap); NBTUtils.writeEnchant(compound, "StoredEnchantments", storedEnchantmentMap);
} }
} }
@NotNull
@Override @Override
public ItemMeta clone() { public ItemMeta clone() {
EnchantedBookMeta enchantedBookMeta = new EnchantedBookMeta(); EnchantedBookMeta enchantedBookMeta = new EnchantedBookMeta();

View File

@ -1,5 +1,6 @@
package net.minestom.server.item.metadata; package net.minestom.server.item.metadata;
import org.jetbrains.annotations.NotNull;
import org.jglrxavpok.hephaistos.nbt.NBTCompound; import org.jglrxavpok.hephaistos.nbt.NBTCompound;
public class FireworkMeta implements ItemMeta { public class FireworkMeta implements ItemMeta {
@ -19,20 +20,21 @@ public class FireworkMeta implements ItemMeta {
} }
@Override @Override
public boolean isSimilar(ItemMeta itemMeta) { public boolean isSimilar(@NotNull ItemMeta itemMeta) {
return false; return false;
} }
@Override @Override
public void read(NBTCompound compound) { public void read(@NotNull NBTCompound compound) {
} }
@Override @Override
public void write(NBTCompound compound) { public void write(@NotNull NBTCompound compound) {
} }
@NotNull
@Override @Override
public ItemMeta clone() { public ItemMeta clone() {
return null; return null;

View File

@ -1,6 +1,7 @@
package net.minestom.server.item.metadata; package net.minestom.server.item.metadata;
import net.minestom.server.item.ItemStack; import net.minestom.server.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jglrxavpok.hephaistos.nbt.NBTCompound; import org.jglrxavpok.hephaistos.nbt.NBTCompound;
/** /**
@ -23,7 +24,7 @@ public interface ItemMeta {
* @param itemMeta the second item meta to check * @param itemMeta the second item meta to check
* @return true if the two meta are similar, false otherwise * @return true if the two meta are similar, false otherwise
*/ */
boolean isSimilar(ItemMeta itemMeta); boolean isSimilar(@NotNull ItemMeta itemMeta);
/** /**
* Reads nbt data from a compound. * Reads nbt data from a compound.
@ -33,14 +34,14 @@ public interface ItemMeta {
* *
* @param compound the compound containing the data * @param compound the compound containing the data
*/ */
void read(NBTCompound compound); void read(@NotNull NBTCompound compound);
/** /**
* Writes nbt data to a compound. * Writes nbt data to a compound.
* *
* @param compound the compound receiving the item meta data * @param compound the compound receiving the item meta data
*/ */
void write(NBTCompound compound); void write(@NotNull NBTCompound compound);
/** /**
* Clones this item meta. * Clones this item meta.
@ -49,6 +50,7 @@ public interface ItemMeta {
* *
* @return the cloned item meta * @return the cloned item meta
*/ */
@NotNull
ItemMeta clone(); ItemMeta clone();
} }

View File

@ -1,6 +1,7 @@
package net.minestom.server.item.metadata; package net.minestom.server.item.metadata;
import net.minestom.server.chat.ChatColor; import net.minestom.server.chat.ChatColor;
import org.jetbrains.annotations.NotNull;
import org.jglrxavpok.hephaistos.nbt.NBTCompound; import org.jglrxavpok.hephaistos.nbt.NBTCompound;
public class LeatherArmorMeta implements ItemMeta { public class LeatherArmorMeta implements ItemMeta {
@ -73,7 +74,7 @@ public class LeatherArmorMeta implements ItemMeta {
} }
@Override @Override
public boolean isSimilar(ItemMeta itemMeta) { public boolean isSimilar(@NotNull ItemMeta itemMeta) {
if (!(itemMeta instanceof LeatherArmorMeta)) if (!(itemMeta instanceof LeatherArmorMeta))
return false; return false;
final LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) itemMeta; final LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) itemMeta;
@ -84,7 +85,7 @@ public class LeatherArmorMeta implements ItemMeta {
} }
@Override @Override
public void read(NBTCompound compound) { public void read(@NotNull NBTCompound compound) {
if (compound.containsKey("display")) { if (compound.containsKey("display")) {
final NBTCompound nbtCompound = compound.getCompound("display"); final NBTCompound nbtCompound = compound.getCompound("display");
if (nbtCompound.containsKey("color")) { if (nbtCompound.containsKey("color")) {
@ -97,7 +98,7 @@ public class LeatherArmorMeta implements ItemMeta {
} }
@Override @Override
public void write(NBTCompound compound) { public void write(@NotNull NBTCompound compound) {
if (modified) { if (modified) {
NBTCompound displayCompound; NBTCompound displayCompound;
if (!compound.containsKey("display")) { if (!compound.containsKey("display")) {
@ -110,6 +111,7 @@ public class LeatherArmorMeta implements ItemMeta {
} }
} }
@NotNull
@Override @Override
public ItemMeta clone() { public ItemMeta clone() {
LeatherArmorMeta leatherArmorMeta = new LeatherArmorMeta(); LeatherArmorMeta leatherArmorMeta = new LeatherArmorMeta();

View File

@ -1,6 +1,7 @@
package net.minestom.server.item.metadata; package net.minestom.server.item.metadata;
import net.minestom.server.chat.ChatColor; import net.minestom.server.chat.ChatColor;
import org.jetbrains.annotations.NotNull;
import org.jglrxavpok.hephaistos.nbt.NBTCompound; import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import org.jglrxavpok.hephaistos.nbt.NBTList; import org.jglrxavpok.hephaistos.nbt.NBTList;
import org.jglrxavpok.hephaistos.nbt.NBTTypes; import org.jglrxavpok.hephaistos.nbt.NBTTypes;
@ -103,7 +104,7 @@ public class MapMeta implements ItemMeta {
} }
@Override @Override
public boolean isSimilar(ItemMeta itemMeta) { public boolean isSimilar(@NotNull ItemMeta itemMeta) {
if (!(itemMeta instanceof MapMeta)) if (!(itemMeta instanceof MapMeta))
return false; return false;
@ -115,7 +116,7 @@ public class MapMeta implements ItemMeta {
} }
@Override @Override
public void read(NBTCompound compound) { public void read(@NotNull NBTCompound compound) {
if (compound.containsKey("map")) { if (compound.containsKey("map")) {
this.mapId = compound.getAsInt("map"); this.mapId = compound.getAsInt("map");
} }
@ -160,7 +161,7 @@ public class MapMeta implements ItemMeta {
} }
@Override @Override
public void write(NBTCompound compound) { public void write(@NotNull NBTCompound compound) {
compound.setInt("map", mapId); compound.setInt("map", mapId);
compound.setInt("map_scale_direction", mapScaleDirection); compound.setInt("map_scale_direction", mapScaleDirection);
@ -191,6 +192,7 @@ public class MapMeta implements ItemMeta {
} }
} }
@NotNull
@Override @Override
public ItemMeta clone() { public ItemMeta clone() {
MapMeta mapMeta = new MapMeta(); MapMeta mapMeta = new MapMeta();

View File

@ -1,6 +1,7 @@
package net.minestom.server.item.metadata; package net.minestom.server.item.metadata;
import net.minestom.server.entity.PlayerSkin; import net.minestom.server.entity.PlayerSkin;
import org.jetbrains.annotations.NotNull;
import org.jglrxavpok.hephaistos.nbt.NBTCompound; import org.jglrxavpok.hephaistos.nbt.NBTCompound;
public class PlayerHeadMeta implements ItemMeta { public class PlayerHeadMeta implements ItemMeta {
@ -14,7 +15,7 @@ public class PlayerHeadMeta implements ItemMeta {
} }
@Override @Override
public boolean isSimilar(ItemMeta itemMeta) { public boolean isSimilar(@NotNull ItemMeta itemMeta) {
if (!(itemMeta instanceof PlayerHeadMeta)) if (!(itemMeta instanceof PlayerHeadMeta))
return false; return false;
final PlayerHeadMeta playerHeadMeta = (PlayerHeadMeta) itemMeta; final PlayerHeadMeta playerHeadMeta = (PlayerHeadMeta) itemMeta;
@ -22,15 +23,16 @@ public class PlayerHeadMeta implements ItemMeta {
} }
@Override @Override
public void read(NBTCompound compound) { public void read(@NotNull NBTCompound compound) {
} }
@Override @Override
public void write(NBTCompound compound) { public void write(@NotNull NBTCompound compound) {
} }
@NotNull
@Override @Override
public ItemMeta clone() { public ItemMeta clone() {
return null; return null;

View File

@ -4,6 +4,7 @@ import net.minestom.server.chat.ChatColor;
import net.minestom.server.potion.CustomPotionEffect; import net.minestom.server.potion.CustomPotionEffect;
import net.minestom.server.potion.PotionType; import net.minestom.server.potion.PotionType;
import net.minestom.server.registry.Registries; import net.minestom.server.registry.Registries;
import org.jetbrains.annotations.NotNull;
import org.jglrxavpok.hephaistos.nbt.NBTCompound; import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import org.jglrxavpok.hephaistos.nbt.NBTList; import org.jglrxavpok.hephaistos.nbt.NBTList;
import org.jglrxavpok.hephaistos.nbt.NBTTypes; import org.jglrxavpok.hephaistos.nbt.NBTTypes;
@ -78,7 +79,7 @@ public class PotionMeta implements ItemMeta {
} }
@Override @Override
public boolean isSimilar(ItemMeta itemMeta) { public boolean isSimilar(@NotNull ItemMeta itemMeta) {
if (!(itemMeta instanceof PotionMeta)) if (!(itemMeta instanceof PotionMeta))
return false; return false;
PotionMeta potionMeta = (PotionMeta) itemMeta; PotionMeta potionMeta = (PotionMeta) itemMeta;
@ -91,7 +92,7 @@ public class PotionMeta implements ItemMeta {
} }
@Override @Override
public void read(NBTCompound compound) { public void read(@NotNull NBTCompound compound) {
if (compound.containsKey("Potion")) { if (compound.containsKey("Potion")) {
this.potionType = Registries.getPotionType(compound.getString("Potion")); this.potionType = Registries.getPotionType(compound.getString("Potion"));
} }
@ -120,7 +121,7 @@ public class PotionMeta implements ItemMeta {
} }
@Override @Override
public void write(NBTCompound compound) { public void write(@NotNull NBTCompound compound) {
if (potionType != null) { if (potionType != null) {
compound.setString("Potion", potionType.getNamespaceID()); compound.setString("Potion", potionType.getNamespaceID());
} }
@ -149,6 +150,7 @@ public class PotionMeta implements ItemMeta {
} }
@NotNull
@Override @Override
public ItemMeta clone() { public ItemMeta clone() {
PotionMeta potionMeta = new PotionMeta(); PotionMeta potionMeta = new PotionMeta();

View File

@ -1,6 +1,7 @@
package net.minestom.server.item.metadata; package net.minestom.server.item.metadata;
import net.minestom.server.entity.EntityType; import net.minestom.server.entity.EntityType;
import org.jetbrains.annotations.NotNull;
import org.jglrxavpok.hephaistos.nbt.NBTCompound; import org.jglrxavpok.hephaistos.nbt.NBTCompound;
// TODO for which item // TODO for which item
@ -14,7 +15,7 @@ public class SpawnEggMeta implements ItemMeta {
} }
@Override @Override
public boolean isSimilar(ItemMeta itemMeta) { public boolean isSimilar(@NotNull ItemMeta itemMeta) {
if (!(itemMeta instanceof SpawnEggMeta)) if (!(itemMeta instanceof SpawnEggMeta))
return false; return false;
final SpawnEggMeta spawnEggMeta = (SpawnEggMeta) itemMeta; final SpawnEggMeta spawnEggMeta = (SpawnEggMeta) itemMeta;
@ -22,14 +23,14 @@ public class SpawnEggMeta implements ItemMeta {
} }
@Override @Override
public void read(NBTCompound compound) { public void read(@NotNull NBTCompound compound) {
if (compound.containsKey("EntityTag")) { if (compound.containsKey("EntityTag")) {
// TODO // TODO
} }
} }
@Override @Override
public void write(NBTCompound compound) { public void write(@NotNull NBTCompound compound) {
if (!hasNbt()) if (!hasNbt())
return; return;
NBTCompound entityCompound = new NBTCompound(); NBTCompound entityCompound = new NBTCompound();
@ -39,6 +40,7 @@ public class SpawnEggMeta implements ItemMeta {
} }
@NotNull
@Override @Override
public ItemMeta clone() { public ItemMeta clone() {
SpawnEggMeta spawnEggMeta = new SpawnEggMeta(); SpawnEggMeta spawnEggMeta = new SpawnEggMeta();

View File

@ -1,5 +1,6 @@
package net.minestom.server.item.metadata; package net.minestom.server.item.metadata;
import org.jetbrains.annotations.NotNull;
import org.jglrxavpok.hephaistos.nbt.NBTCompound; import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import org.jglrxavpok.hephaistos.nbt.NBTList; import org.jglrxavpok.hephaistos.nbt.NBTList;
import org.jglrxavpok.hephaistos.nbt.NBTString; import org.jglrxavpok.hephaistos.nbt.NBTString;
@ -37,7 +38,7 @@ public class WritableBookMeta implements ItemMeta {
} }
@Override @Override
public boolean isSimilar(ItemMeta itemMeta) { public boolean isSimilar(@NotNull ItemMeta itemMeta) {
if (!(itemMeta instanceof WritableBookMeta)) if (!(itemMeta instanceof WritableBookMeta))
return false; return false;
final WritableBookMeta writableBookMeta = (WritableBookMeta) itemMeta; final WritableBookMeta writableBookMeta = (WritableBookMeta) itemMeta;
@ -45,7 +46,7 @@ public class WritableBookMeta implements ItemMeta {
} }
@Override @Override
public void read(NBTCompound compound) { public void read(@NotNull NBTCompound compound) {
if (compound.containsKey("pages")) { if (compound.containsKey("pages")) {
final NBTList<NBTString> list = compound.getList("pages"); final NBTList<NBTString> list = compound.getList("pages");
for (NBTString page : list) { for (NBTString page : list) {
@ -55,7 +56,7 @@ public class WritableBookMeta implements ItemMeta {
} }
@Override @Override
public void write(NBTCompound compound) { public void write(@NotNull NBTCompound compound) {
if (!pages.isEmpty()) { if (!pages.isEmpty()) {
NBTList<NBTString> list = new NBTList<>(NBTTypes.TAG_String); NBTList<NBTString> list = new NBTList<>(NBTTypes.TAG_String);
for (String page : pages) { for (String page : pages) {
@ -65,6 +66,7 @@ public class WritableBookMeta implements ItemMeta {
} }
} }
@NotNull
@Override @Override
public ItemMeta clone() { public ItemMeta clone() {
WritableBookMeta writableBookMeta = new WritableBookMeta(); WritableBookMeta writableBookMeta = new WritableBookMeta();

View File

@ -2,6 +2,7 @@ package net.minestom.server.item.metadata;
import net.minestom.server.chat.ChatParser; import net.minestom.server.chat.ChatParser;
import net.minestom.server.chat.ColoredText; import net.minestom.server.chat.ColoredText;
import org.jetbrains.annotations.NotNull;
import org.jglrxavpok.hephaistos.nbt.NBTCompound; import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import org.jglrxavpok.hephaistos.nbt.NBTList; import org.jglrxavpok.hephaistos.nbt.NBTList;
import org.jglrxavpok.hephaistos.nbt.NBTString; import org.jglrxavpok.hephaistos.nbt.NBTString;
@ -118,7 +119,7 @@ public class WrittenBookMeta implements ItemMeta {
} }
@Override @Override
public boolean isSimilar(ItemMeta itemMeta) { public boolean isSimilar(@NotNull ItemMeta itemMeta) {
if (!(itemMeta instanceof WrittenBookMeta)) if (!(itemMeta instanceof WrittenBookMeta))
return false; return false;
final WrittenBookMeta writtenBookMeta = (WrittenBookMeta) itemMeta; final WrittenBookMeta writtenBookMeta = (WrittenBookMeta) itemMeta;
@ -130,7 +131,7 @@ public class WrittenBookMeta implements ItemMeta {
} }
@Override @Override
public void read(NBTCompound compound) { public void read(@NotNull NBTCompound compound) {
if (compound.containsKey("resolved")) { if (compound.containsKey("resolved")) {
this.resolved = compound.getByte("resolved") == 1; this.resolved = compound.getByte("resolved") == 1;
} }
@ -154,7 +155,7 @@ public class WrittenBookMeta implements ItemMeta {
} }
@Override @Override
public void write(NBTCompound compound) { public void write(@NotNull NBTCompound compound) {
if (resolved) { if (resolved) {
compound.setByte("resolved", (byte) 1); compound.setByte("resolved", (byte) 1);
} }
@ -176,6 +177,7 @@ public class WrittenBookMeta implements ItemMeta {
} }
} }
@NotNull
@Override @Override
public ItemMeta clone() { public ItemMeta clone() {
WrittenBookMeta writtenBookMeta = new WrittenBookMeta(); WrittenBookMeta writtenBookMeta = new WrittenBookMeta();

View File

@ -3,6 +3,7 @@ package net.minestom.server.scoreboard;
import net.minestom.server.entity.Player; import net.minestom.server.entity.Player;
import net.minestom.server.network.packet.server.play.ScoreboardObjectivePacket; import net.minestom.server.network.packet.server.play.ScoreboardObjectivePacket;
import net.minestom.server.network.player.PlayerConnection; import net.minestom.server.network.player.PlayerConnection;
import org.jetbrains.annotations.NotNull;
import java.util.Collections; import java.util.Collections;
import java.util.Set; import java.util.Set;
@ -41,7 +42,7 @@ public class BelowNameTag implements Scoreboard {
} }
@Override @Override
public boolean addViewer(Player player) { public boolean addViewer(@NotNull Player player) {
boolean result = this.viewers.add(player); boolean result = this.viewers.add(player);
PlayerConnection connection = player.getPlayerConnection(); PlayerConnection connection = player.getPlayerConnection();
@ -56,7 +57,7 @@ public class BelowNameTag implements Scoreboard {
} }
@Override @Override
public boolean removeViewer(Player player) { public boolean removeViewer(@NotNull Player player) {
boolean result = this.viewers.remove(player); boolean result = this.viewers.remove(player);
PlayerConnection connection = player.getPlayerConnection(); PlayerConnection connection = player.getPlayerConnection();
@ -68,6 +69,7 @@ public class BelowNameTag implements Scoreboard {
return result; return result;
} }
@NotNull
@Override @Override
public Set<Player> getViewers() { public Set<Player> getViewers() {
return Collections.unmodifiableSet(viewers); return Collections.unmodifiableSet(viewers);

View File

@ -10,6 +10,7 @@ import net.minestom.server.network.packet.server.play.TeamsPacket;
import net.minestom.server.network.packet.server.play.UpdateScorePacket; import net.minestom.server.network.packet.server.play.UpdateScorePacket;
import net.minestom.server.network.player.PlayerConnection; import net.minestom.server.network.player.PlayerConnection;
import net.minestom.server.utils.validate.Check; import net.minestom.server.utils.validate.Check;
import org.jetbrains.annotations.NotNull;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
@ -177,7 +178,7 @@ public class Sidebar implements Scoreboard {
} }
@Override @Override
public boolean addViewer(Player player) { public boolean addViewer(@NotNull Player player) {
final boolean result = this.viewers.add(player); final boolean result = this.viewers.add(player);
PlayerConnection playerConnection = player.getPlayerConnection(); PlayerConnection playerConnection = player.getPlayerConnection();
@ -195,7 +196,7 @@ public class Sidebar implements Scoreboard {
} }
@Override @Override
public boolean removeViewer(Player player) { public boolean removeViewer(@NotNull Player player) {
final boolean result = this.viewers.remove(player); final boolean result = this.viewers.remove(player);
PlayerConnection playerConnection = player.getPlayerConnection(); PlayerConnection playerConnection = player.getPlayerConnection();
ScoreboardObjectivePacket scoreboardObjectivePacket = this.getDestructionObjectivePacket(); ScoreboardObjectivePacket scoreboardObjectivePacket = this.getDestructionObjectivePacket();
@ -208,6 +209,7 @@ public class Sidebar implements Scoreboard {
return result; return result;
} }
@NotNull
@Override @Override
public Set<Player> getViewers() { public Set<Player> getViewers() {
return viewers; return viewers;

View File

@ -3,6 +3,7 @@ package net.minestom.server.scoreboard;
import net.minestom.server.entity.Player; import net.minestom.server.entity.Player;
import net.minestom.server.network.packet.server.play.ScoreboardObjectivePacket; import net.minestom.server.network.packet.server.play.ScoreboardObjectivePacket;
import net.minestom.server.network.player.PlayerConnection; import net.minestom.server.network.player.PlayerConnection;
import org.jetbrains.annotations.NotNull;
import java.util.Collections; import java.util.Collections;
import java.util.Set; import java.util.Set;
@ -49,7 +50,7 @@ public class TabList implements Scoreboard {
} }
@Override @Override
public boolean addViewer(Player player) { public boolean addViewer(@NotNull Player player) {
boolean result = this.viewers.add(player); boolean result = this.viewers.add(player);
PlayerConnection connection = player.getPlayerConnection(); PlayerConnection connection = player.getPlayerConnection();
@ -62,7 +63,7 @@ public class TabList implements Scoreboard {
} }
@Override @Override
public boolean removeViewer(Player player) { public boolean removeViewer(@NotNull Player player) {
boolean result = this.viewers.remove(player); boolean result = this.viewers.remove(player);
PlayerConnection connection = player.getPlayerConnection(); PlayerConnection connection = player.getPlayerConnection();
@ -73,6 +74,7 @@ public class TabList implements Scoreboard {
return result; return result;
} }
@NotNull
@Override @Override
public Set<Player> getViewers() { public Set<Player> getViewers() {
return Collections.unmodifiableSet(this.viewers); return Collections.unmodifiableSet(this.viewers);