Skip to content

Commit 1003fd6

Browse files
committed
Clean up Javadocs, more enforcing of NonNull arguments
1 parent 0927191 commit 1003fd6

File tree

8 files changed

+66
-23
lines changed

8 files changed

+66
-23
lines changed

api/src/main/java/org/geysermc/geyser/api/bedrock/camera/CameraData.java

+24-16
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,36 @@
2727

2828
import org.checkerframework.checker.nullness.qual.NonNull;
2929
import org.checkerframework.checker.nullness.qual.Nullable;
30+
import org.geysermc.geyser.api.connection.GeyserConnection;
3031

3132
import java.util.Set;
3233
import java.util.UUID;
3334

35+
/**
36+
* This interface holds all the methods that relate to a client's camera.
37+
* Can be accessed through {@link GeyserConnection#camera()}.
38+
*/
3439
public interface CameraData {
3540

3641
/**
37-
* Sends a camera instruction to the client.
42+
* Sends a camera fade instruction to the client.
3843
* If an existing camera fade is already in progress, the current fade will be prolonged.
3944
* Can be built using {@link CameraFade.Builder}.
45+
* To stop a fade early, use {@link #clearCameraInstructions()}.
4046
*
41-
* @param fade the camera fade to send
47+
* @param fade the camera fade instruction to send
4248
*/
4349
void sendCameraFade(@NonNull CameraFade fade);
4450

4551
/**
46-
* Sends a camera instruction to the client.
47-
* If an existing camera movement is already in progress:
48-
* The (optional) camera fade will be added on top of the existing fade, and
49-
* the final camera position will be the one of the latest instruction.
52+
* Sends a camera position instruction to the client.
53+
* If an existing camera movement is already in progress,
54+
* the final camera position will be the one of the latest instruction, and
55+
* the (optional) camera fade will be added on top of the existing fade.
5056
* Can be built using {@link CameraPosition.Builder}.
57+
* To stop reset the camera position/stop ongoing instructions, use {@link #clearCameraInstructions()}.
5158
*
52-
* @param position the camera position to send
59+
* @param position the camera position instruction to send
5360
*/
5461
void sendCameraPosition(@NonNull CameraPosition position);
5562

@@ -60,8 +67,8 @@ public interface CameraData {
6067
void clearCameraInstructions();
6168

6269
/**
63-
* Forces a {@link CameraPerspective} on the client. This will prevent
64-
* the client from changing their camera perspective until it is unlocked via {@link #clearCameraInstructions()}.
70+
* Forces a {@link CameraPerspective} on the client. This will prevent the client
71+
* from changing their camera perspective until it is unlocked via {@link #clearCameraInstructions()}.
6572
* <p>
6673
* Note: You cannot force a client into a free camera perspective with this method.
6774
* To do that, send a {@link CameraPosition} via {@link #sendCameraPosition(CameraPosition)} - it requires a set position
@@ -72,16 +79,17 @@ public interface CameraData {
7279
void forceCameraPerspective(@NonNull CameraPerspective perspective);
7380

7481
/**
75-
* Gets the client's current {@link CameraPerspective}, if forced.
82+
* Gets the client's current {@link CameraPerspective}, if one is currently forced.
7683
* This will return {@code null} if the client is not currently forced into a perspective.
77-
* If a perspective is forced, the client will not be able to change their camera perspective until it is unlocked
84+
* If a perspective is forced, the client will not be able to change their camera perspective until it is unlocked.
7885
*
7986
* @return the forced perspective, or {@code null} if none is forced.
8087
*/
8188
@Nullable CameraPerspective forcedCameraPerspective();
8289

8390
/**
84-
* Shakes the client's camera.<br><br>
91+
* Shakes the client's camera.
92+
* <p>
8593
* If the camera is already shaking with the same {@link CameraShake} type, then the additional intensity
8694
* will be layered on top of the existing intensity, with their own distinct durations.<br>
8795
* If the existing shake type is different and the new intensity/duration are not positive, the existing shake only
@@ -94,7 +102,7 @@ public interface CameraData {
94102
void shakeCamera(float intensity, float duration, @NonNull CameraShake type);
95103

96104
/**
97-
* Stops all camera shake of any type.
105+
* Stops all camera shakes of any type.
98106
*/
99107
void stopCameraShake();
100108

@@ -123,18 +131,18 @@ public interface CameraData {
123131
/**
124132
* (Un)locks the client's camera, so that they cannot look around.
125133
* To ensure the camera is only unlocked when all locks are released, you must supply
126-
* a UUID-key to this method, and use the same key to unlock the camera.
134+
* a UUID when using method, and use the same UUID to unlock the camera.
127135
*
128136
* @param lock whether to lock the camera
129-
* @param owner the owner of the lock
137+
* @param owner the owner of the lock, represented with a UUID
130138
* @return if the camera is locked after this method call
131139
*/
132140
boolean lockCamera(boolean lock, @NonNull UUID owner);
133141

134142
/**
135143
* Returns whether the client's camera is locked.
136144
*
137-
* @return whether the camera is locked
145+
* @return whether the camera is currently locked
138146
*/
139147
boolean isCameraLocked();
140148
}

api/src/main/java/org/geysermc/geyser/api/bedrock/camera/CameraEaseType.java

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525

2626
package org.geysermc.geyser.api.bedrock.camera;
2727

28+
/**
29+
* These are all the easing types that can be used when sending a {@link CameraPosition} instruction.
30+
* When using these, the client won't teleport to the new camera position, but instead transition to it.
31+
* <p>
32+
* See <a href="https://easings.net/">https://easings.net/</a>.</a> for more information.
33+
*/
2834
public enum CameraEaseType {
2935
LINEAR("linear"),
3036
SPRING("spring"),

api/src/main/java/org/geysermc/geyser/api/bedrock/camera/CameraFade.java

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
/**
3535
* Represents a coloured fade overlay on the camera.
36+
* <p>
37+
* Can be sent with {@link CameraData#sendCameraFade(CameraFade)}, or with a {@link CameraPosition} instruction.
3638
*/
3739
public interface CameraFade {
3840

api/src/main/java/org/geysermc/geyser/api/bedrock/camera/CameraPosition.java

+9
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@
3131
import org.cloudburstmc.math.vector.Vector3f;
3232
import org.geysermc.geyser.api.GeyserApi;
3333

34+
/**
35+
* This interface represents a camera position instruction. Can be built with the {@link #builder()}.
36+
* <p>
37+
* Any camera position instruction pins the client camera to a specific position and rotation.
38+
* You can set {@link CameraEaseType} to ensure a smooth transition that will last {@link #easeDuration()} seconds.
39+
* A {@link CameraFade} can also be sent, which will transition the player to a coloured transition during the transition.
40+
* <p>
41+
* Use {@link CameraData#sendCameraPosition(CameraPosition)} to send such an instruction to any connection.
42+
*/
3443
public interface CameraPosition {
3544

3645
/**

api/src/main/java/org/geysermc/geyser/api/bedrock/camera/CameraShake.java

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525

2626
package org.geysermc.geyser.api.bedrock.camera;
2727

28+
/**
29+
* Represents a camera shake instruction. Can be sent in {@link CameraData#shakeCamera(float, float, CameraShake)}
30+
*/
2831
public enum CameraShake {
2932
POSITIONAL,
3033
ROTATIONAL

api/src/main/java/org/geysermc/geyser/api/entity/EntityData.java

+12-5
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,22 @@
2828
import org.checkerframework.checker.index.qual.NonNegative;
2929
import org.checkerframework.checker.nullness.qual.NonNull;
3030
import org.checkerframework.checker.nullness.qual.Nullable;
31+
import org.geysermc.geyser.api.connection.GeyserConnection;
3132
import org.geysermc.geyser.api.entity.type.GeyserEntity;
3233
import org.geysermc.geyser.api.entity.type.player.GeyserPlayerEntity;
3334

3435
import java.util.UUID;
3536
import java.util.concurrent.CompletableFuture;
3637

38+
/**
39+
* This class holds all the methods that relate to entities.
40+
* Can be accessed through {@link GeyserConnection#entities()}.
41+
*/
3742
public interface EntityData {
3843

3944
/**
45+
* Returns a {@link GeyserEntity} to e.g. make them play an emote.
46+
*
4047
* @param javaId the Java entity ID to look up.
4148
* @return a {@link GeyserEntity} if present in this connection's entity tracker.
4249
*/
@@ -51,7 +58,7 @@ public interface EntityData {
5158
void showEmote(@NonNull GeyserPlayerEntity emoter, @NonNull String emoteId);
5259

5360
/**
54-
* Returns the {@link GeyserPlayerEntity} of this connection.
61+
* Gets the {@link GeyserPlayerEntity} of this connection.
5562
*
5663
* @return the {@link GeyserPlayerEntity} of this connection.
5764
*/
@@ -60,18 +67,18 @@ public interface EntityData {
6067
/**
6168
* (Un)locks the client's movement inputs, so that they cannot move.
6269
* To ensure that movement is only unlocked when all locks are released, you must supply
63-
* a UUID-key to this method, and use the same key to unlock the camera.
70+
* a UUID with this method, and use the same UUID to unlock the camera.
6471
*
65-
* @param lock whether to lock the camera
72+
* @param lock whether to lock the movement
6673
* @param owner the owner of the lock
6774
* @return if the movement is locked after this method call
6875
*/
6976
boolean lockMovement(boolean lock, @NonNull UUID owner);
7077

7178
/**
72-
* Returns whether the client's camera is locked.
79+
* Returns whether the client's movement is currently locked.
7380
*
74-
* @return whether the camera is locked
81+
* @return whether the movement is locked
7582
*/
7683
boolean isMovementLocked();
7784
}

core/src/main/java/org/geysermc/geyser/impl/camera/GeyserCameraFade.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public record GeyserCameraFade(
3636
float fadeInSeconds,
3737
float holdSeconds,
3838
float fadeOutSeconds
39-
) implements CameraFade {
4039

40+
) implements CameraFade {
4141
public static class Builder implements CameraFade.Builder {
4242
private Color color;
4343
private float fadeInSeconds;
@@ -46,6 +46,10 @@ public static class Builder implements CameraFade.Builder {
4646

4747
@Override
4848
public CameraFade.Builder color(@NonNull Color color) {
49+
//noinspection ConstantValue
50+
if (color == null) {
51+
throw new IllegalArgumentException("Color cannot be null!");
52+
}
4953
this.color = color;
5054
return this;
5155
}

core/src/main/java/org/geysermc/geyser/impl/camera/GeyserCameraPosition.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,15 @@ public CameraPosition.Builder easeType(@Nullable CameraEaseType easeType) {
8282
@Override
8383
public CameraPosition.Builder easeDuration(float easeDuration) {
8484
if (easeDuration < 0) {
85-
throw new IllegalArgumentException("Camera ease duration cannot be negative");
85+
throw new IllegalArgumentException("Camera ease duration cannot be negative!");
8686
}
8787
this.easeDuration = easeDuration;
8888
return this;
8989
}
9090

9191
@Override
9292
public CameraPosition.Builder position(@NonNull Vector3f position) {
93+
//noinspection ConstantValue
9394
if (position == null) {
9495
throw new IllegalArgumentException("Camera position cannot be null");
9596
}
@@ -99,6 +100,9 @@ public CameraPosition.Builder position(@NonNull Vector3f position) {
99100

100101
@Override
101102
public CameraPosition.Builder rotationX(int rotationX) {
103+
if (rotationX < -90 || rotationX > 90) {
104+
throw new IllegalArgumentException("X-axis rotation needs to be between -90 and 90 degrees.");
105+
}
102106
this.rotationX = rotationX;
103107
return this;
104108
}

0 commit comments

Comments
 (0)