Added some comments about exceptions

This commit is contained in:
themode 2020-11-07 04:42:48 +01:00
parent 1d30e6e953
commit 7bdfc93334
5 changed files with 25 additions and 5 deletions

View File

@ -595,10 +595,13 @@ public class MinecraftServer {
/** /**
* Starts the server. * Starts the server.
* <p>
* It should be called after {@link #init()} and probably your own initialization code.
* *
* @param address the server address * @param address the server address
* @param port the server port * @param port the server port
* @param responseDataConsumer the response data consumer, can be null * @param responseDataConsumer the response data consumer, can be null
* @throws IllegalStateException if called before {@link #init()} or if the server is already running
*/ */
public void start(String address, int port, ResponseDataConsumer responseDataConsumer) { public void start(String address, int port, ResponseDataConsumer responseDataConsumer) {
Check.stateCondition(!initialized, "#start can only be called after #init"); Check.stateCondition(!initialized, "#start can only be called after #init");
@ -627,6 +630,7 @@ public class MinecraftServer {
* *
* @param address the server address * @param address the server address
* @param port the server port * @param port the server port
* @see #start(String, int, ResponseDataConsumer)
*/ */
public void start(String address, int port) { public void start(String address, int port) {
start(address, port, null); start(address, port, null);

View File

@ -242,6 +242,14 @@ public class ChatColor {
return codeName; return codeName;
} }
/**
* Gets the color id, only present if this color has been retrieved from {@link ChatColor} constants.
* <p>
* Should only be used for some special packets which require it.
*
* @return the color id
* @throws IllegalStateException if the color is not from the class constants
*/
public int getId() { public int getId() {
Check.stateCondition(id == -1, "Please use one of the ChatColor constant instead"); Check.stateCondition(id == -1, "Please use one of the ChatColor constant instead");
return id; return id;
@ -263,7 +271,7 @@ public class ChatColor {
code = codeName; code = codeName;
} else { } else {
// RGB color (special code not set) // RGB color (special code not set)
int color = (red & 0xFF) << 16 | (green & 0xFF) << 8 | blue & 0xFF; final int color = (red & 0xFF) << 16 | (green & 0xFF) << 8 | blue & 0xFF;
code = Integer.toHexString(color); code = Integer.toHexString(color);
} }

View File

@ -1029,6 +1029,7 @@ public class Player extends LivingEntity implements CommandSender {
* Sets and refresh client food bar. * Sets and refresh client food bar.
* *
* @param food the new food value * @param food the new food value
* @throws IllegalArgumentException if {@code food} is not between 0 and 20
*/ */
public void setFood(int food) { public void setFood(int food) {
Check.argCondition(!MathUtils.isBetween(food, 0, 20), "Food has to be between 0 and 20"); Check.argCondition(!MathUtils.isBetween(food, 0, 20), "Food has to be between 0 and 20");
@ -1044,6 +1045,7 @@ public class Player extends LivingEntity implements CommandSender {
* Sets and refresh client food saturation. * Sets and refresh client food saturation.
* *
* @param foodSaturation the food saturation * @param foodSaturation the food saturation
* @throws IllegalArgumentException if {@code foodSaturation} is not between 0 and 5
*/ */
public void setFoodSaturation(float foodSaturation) { public void setFoodSaturation(float foodSaturation) {
Check.argCondition(!MathUtils.isBetween(foodSaturation, 0, 5), "Food saturation has to be between 0 and 5"); Check.argCondition(!MathUtils.isBetween(foodSaturation, 0, 5), "Food saturation has to be between 0 and 5");
@ -1218,7 +1220,7 @@ public class Player extends LivingEntity implements CommandSender {
* *
* @param resourcePack the resource pack * @param resourcePack the resource pack
*/ */
public void setResourcePack(ResourcePack resourcePack) { public void setResourcePack(@NotNull ResourcePack resourcePack) {
Check.notNull(resourcePack, "The resource pack cannot be null"); Check.notNull(resourcePack, "The resource pack cannot be null");
final String url = resourcePack.getUrl(); final String url = resourcePack.getUrl();
final String hash = resourcePack.getHash(); final String hash = resourcePack.getHash();
@ -1367,6 +1369,7 @@ public class Player extends LivingEntity implements CommandSender {
* This cannot change the displayed level, see {@link #setLevel(int)}. * This cannot change the displayed level, see {@link #setLevel(int)}.
* *
* @param exp a percentage between 0 and 1 * @param exp a percentage between 0 and 1
* @throws IllegalArgumentException if {@code exp} is not between 0 and 1
*/ */
public void setExp(float exp) { public void setExp(float exp) {
Check.argCondition(!MathUtils.isBetween(exp, 0, 1), "Exp should be between 0 and 1"); Check.argCondition(!MathUtils.isBetween(exp, 0, 1), "Exp should be between 0 and 1");
@ -1880,6 +1883,7 @@ public class Player extends LivingEntity implements CommandSender {
* Changes the player permission level. * Changes the player permission level.
* *
* @param permissionLevel the new player permission level * @param permissionLevel the new player permission level
* @throws IllegalArgumentException if {@code permissionLevel} is not between 0 and 4
*/ */
public void setPermissionLevel(int permissionLevel) { public void setPermissionLevel(int permissionLevel) {
Check.argCondition(!MathUtils.isBetween(permissionLevel, 0, 4), "permissionLevel has to be between 0 and 4"); Check.argCondition(!MathUtils.isBetween(permissionLevel, 0, 4), "permissionLevel has to be between 0 and 4");

View File

@ -259,6 +259,7 @@ public final class ConnectionManager {
* Used during disconnection, you shouldn't have to do it manually. * Used during disconnection, you shouldn't have to do it manually.
* *
* @param connection the player connection * @param connection the player connection
* @see PlayerConnection#disconnect() to properly disconnect a player
*/ */
public void removePlayer(@NotNull PlayerConnection connection) { public void removePlayer(@NotNull PlayerConnection connection) {
final Player player = this.connectionPlayerMap.get(connection); final Player player = this.connectionPlayerMap.get(connection);

View File

@ -86,9 +86,12 @@ public class Sidebar implements Scoreboard {
} }
/** /**
* Creates a new {@link ScoreboardLine} * Creates a new {@link ScoreboardLine}.
* *
* @param scoreboardLine The new scoreboard line * @param scoreboardLine the new scoreboard line
* @throws IllegalStateException if the sidebar cannot take more line
* @throws IllegalArgumentException if the sidebar already contains the line {@code scoreboardLine}
* or has a line with the same id
*/ */
public void createLine(ScoreboardLine scoreboardLine) { public void createLine(ScoreboardLine scoreboardLine) {
synchronized (lines) { synchronized (lines) {
@ -114,7 +117,7 @@ public class Sidebar implements Scoreboard {
} }
/** /**
* Updates a {@link ScoreboardLine} content through the given identifier * Updates a {@link ScoreboardLine} content through the given identifier.
* *
* @param id The identifier of the {@link ScoreboardLine} * @param id The identifier of the {@link ScoreboardLine}
* @param content The new content for the {@link ScoreboardLine} * @param content The new content for the {@link ScoreboardLine}