Skip to content

Commit a9e53bb

Browse files
committed
final docs changes
1 parent dec545e commit a9e53bb

5 files changed

Lines changed: 48 additions & 12 deletions

File tree

api/src/main/java/com/lunarclient/apollo/module/cosmetic/Cosmetic.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import lombok.Builder;
3232
import lombok.Getter;
3333
import org.jetbrains.annotations.Nullable;
34+
import org.jetbrains.annotations.Range;
3435

3536
/**
3637
* Represents a single cosmetic with optional per-type display settings.
@@ -44,10 +45,12 @@ public final class Cosmetic {
4445
/**
4546
* Returns the Lunar Client cosmetic id for this entry.
4647
*
48+
* <p>The value must be greater than 0.</p>
49+
*
4750
* @return the cosmetic id
4851
* @since 1.2.6
4952
*/
50-
int id;
53+
@Range(from = 1, to = Integer.MAX_VALUE) int id;
5154

5255
/**
5356
* Returns optional cosmetic display options for this cosmetic id.

api/src/main/java/com/lunarclient/apollo/module/cosmetic/CosmeticModule.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
import java.util.List;
3636
import java.util.UUID;
3737
import org.jetbrains.annotations.ApiStatus;
38+
import org.jetbrains.annotations.Nullable;
39+
import org.jetbrains.annotations.Range;
3840

3941
/**
4042
* Represents the cosmetic module.
@@ -87,21 +89,26 @@ public abstract class CosmeticModule extends ApolloModule {
8789
/**
8890
* Removes every instance of a spray id for the given {@link Recipients}.
8991
*
92+
* <p>The spray id must be greater than 0.</p>
93+
*
9094
* @param recipients the recipients that are receiving the packet
9195
* @param sprayId the spray cosmetic id
9296
* @since 1.2.6
9397
*/
94-
public abstract void removeSpray(Recipients recipients, int sprayId);
98+
public abstract void removeSpray(Recipients recipients, @Range(from = 1, to = Integer.MAX_VALUE) int sprayId);
9599

96100
/**
97101
* Removes every instance of a spray id at a specific block for the given {@link Recipients}.
98102
*
103+
* <p>The spray id must be greater than 0. If {@code location} is {@code null}, every
104+
* instance of the spray id is removed regardless of position.</p>
105+
*
99106
* @param recipients the recipients that are receiving the packet
100107
* @param sprayId the spray cosmetic id
101-
* @param location the block location of the spray to remove
108+
* @param location the block location of the spray to remove, or {@code null} to remove all
102109
* @since 1.2.6
103110
*/
104-
public abstract void removeSpray(Recipients recipients, int sprayId, ApolloBlockLocation location);
111+
public abstract void removeSpray(Recipients recipients, @Range(from = 1, to = Integer.MAX_VALUE) int sprayId, @Nullable ApolloBlockLocation location);
105112

106113
/**
107114
* Resets all server sprays for the given {@link Recipients}.

api/src/main/java/com/lunarclient/apollo/module/cosmetic/Spray.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.time.Duration;
2929
import lombok.Builder;
3030
import lombok.Getter;
31+
import org.jetbrains.annotations.Range;
3132

3233
/**
3334
* Represents a spray.
@@ -45,10 +46,12 @@ public final class Spray {
4546
/**
4647
* Returns the Lunar Client spray cosmetic id.
4748
*
49+
* <p>The value must be greater than 0.</p>
50+
*
4851
* @return the spray cosmetic id
4952
* @since 1.2.6
5053
*/
51-
int sprayId;
54+
@Range(from = 1, to = Integer.MAX_VALUE) int sprayId;
5255

5356
/**
5457
* Returns the {@link ApolloBlockLocation} of the block the spray is placed on.
@@ -78,8 +81,6 @@ public final class Spray {
7881
/**
7982
* Returns the {@link Duration} for how long the spray remains visible on the client.
8083
*
81-
* <p>Maximum duration is 600 seconds (10 minutes).</p>
82-
*
8384
* @return the display duration
8485
* @since 1.2.6
8586
*/

common/src/main/java/com/lunarclient/apollo/module/cosmetic/CosmeticModuleImpl.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
import lombok.NonNull;
4545
import org.jetbrains.annotations.Nullable;
4646

47+
import static com.lunarclient.apollo.util.Ranges.checkStrictlyPositive;
48+
4749
/**
4850
* Provides the cosmetic module.
4951
*
@@ -67,9 +69,13 @@ public void equipNpcCosmetics(@NonNull Recipients recipients, @NonNull UUID npcU
6769

6870
@Override
6971
public void unequipNpcCosmetics(@NonNull Recipients recipients, @NonNull UUID npcUuid, @NonNull List<Integer> cosmeticIds) {
72+
List<Integer> validatedIds = cosmeticIds.stream()
73+
.map(id -> checkStrictlyPositive(id, "Cosmetic#id"))
74+
.collect(Collectors.toList());
75+
7076
UnequipNpcCosmeticsMessage message = UnequipNpcCosmeticsMessage.newBuilder()
7177
.setNpcUuid(NetworkTypes.toProtobuf(npcUuid))
72-
.addAllCosmeticIds(cosmeticIds)
78+
.addAllCosmeticIds(validatedIds)
7379
.build();
7480

7581
recipients.forEach(player -> ((AbstractApolloPlayer) player).sendPacket(message));
@@ -87,7 +93,7 @@ public void resetNpcCosmetics(@NonNull Recipients recipients, @NonNull UUID npcU
8793
@Override
8894
public void displaySpray(@NonNull Recipients recipients, @NonNull Spray spray) {
8995
DisplaySprayMessage message = DisplaySprayMessage.newBuilder()
90-
.setSprayId(spray.getSprayId())
96+
.setSprayId(checkStrictlyPositive(spray.getSprayId(), "Spray#sprayId"))
9197
.setLocation(NetworkTypes.toProtobuf(spray.getLocation()))
9298
.setFacing(NetworkTypes.toProtobuf(spray.getFacing()))
9399
.setRotation(spray.getRotation())
@@ -100,7 +106,7 @@ public void displaySpray(@NonNull Recipients recipients, @NonNull Spray spray) {
100106
@Override
101107
public void removeSpray(@NonNull Recipients recipients, int sprayId) {
102108
RemoveSprayMessage message = RemoveSprayMessage.newBuilder()
103-
.setSprayId(sprayId)
109+
.setSprayId(checkStrictlyPositive(sprayId, "Spray#sprayId"))
104110
.build();
105111

106112
recipients.forEach(player -> ((AbstractApolloPlayer) player).sendPacket(message));
@@ -109,7 +115,7 @@ public void removeSpray(@NonNull Recipients recipients, int sprayId) {
109115
@Override
110116
public void removeSpray(@NonNull Recipients recipients, int sprayId, @Nullable ApolloBlockLocation location) {
111117
RemoveSprayMessage.Builder builder = RemoveSprayMessage.newBuilder()
112-
.setSprayId(sprayId);
118+
.setSprayId(checkStrictlyPositive(sprayId, "Spray#sprayId"));
113119

114120
if (location != null) {
115121
builder.setLocation(NetworkTypes.toProtobuf(location));
@@ -127,9 +133,13 @@ public void resetSprays(@NonNull Recipients recipients) {
127133

128134
private com.lunarclient.apollo.cosmetic.v1.Cosmetic toProtobuf(Cosmetic cosmetic) {
129135
com.lunarclient.apollo.cosmetic.v1.Cosmetic.Builder builder = com.lunarclient.apollo.cosmetic.v1.Cosmetic.newBuilder()
130-
.setId(cosmetic.getId());
136+
.setId(checkStrictlyPositive(cosmetic.getId(), "Cosmetic#id"));
131137

132138
CosmeticOptions options = cosmetic.getOptions();
139+
if (options == null) {
140+
return builder.build();
141+
}
142+
133143
if (options instanceof HatOptions) {
134144
HatOptions hatOptions = (HatOptions) options;
135145
builder.setHatOptions(com.lunarclient.apollo.cosmetic.v1.HatOptions.newBuilder()

common/src/main/java/com/lunarclient/apollo/util/Ranges.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ public static int checkPositive(int value, String name) {
6262
return value;
6363
}
6464

65+
/**
66+
* Returns the value if it is strictly positive (greater than 0),
67+
* otherwise throws an {@link IllegalArgumentException}.
68+
*
69+
* @param value the value to check
70+
* @param name the name of the value
71+
* @return the value
72+
* @throws IllegalArgumentException if the value is not strictly positive
73+
* @since 1.2.6
74+
*/
75+
public static int checkStrictlyPositive(int value, String name) {
76+
if(value <= 0) throw new IllegalArgumentException(name + " must be greater than 0");
77+
return value;
78+
}
79+
6580
/**
6681
* Returns the value if it is positive, otherwise throws an
6782
* {@link IllegalArgumentException}.

0 commit comments

Comments
 (0)