Skip to content

Commit bd91daf

Browse files
committed
Implement CooldownStyle
1 parent 87e8be8 commit bd91daf

12 files changed

Lines changed: 311 additions & 19 deletions

File tree

api/src/main/java/com/lunarclient/apollo/module/cooldown/Cooldown.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.time.Duration;
2828
import lombok.Builder;
2929
import lombok.Getter;
30+
import org.jetbrains.annotations.Nullable;
3031

3132
/**
3233
* Represents a cooldown which can be shown on the client.
@@ -64,4 +65,14 @@ public final class Cooldown {
6465
*/
6566
Icon icon;
6667

68+
/**
69+
* Returns the cooldown {@link CooldownStyle}.
70+
*
71+
* <p>If {@code null}, the style defaults to the user's local Cooldown Mod settings.</p>
72+
*
73+
* @return the cooldown style
74+
* @since 1.2.5
75+
*/
76+
@Nullable CooldownStyle style;
77+
6778
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* This file is part of Apollo, licensed under the MIT License.
3+
*
4+
* Copyright (c) 2026 Moonsworth
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.lunarclient.apollo.module.cooldown;
25+
26+
import java.awt.Color;
27+
import lombok.Builder;
28+
import lombok.Getter;
29+
import org.jetbrains.annotations.Nullable;
30+
31+
/**
32+
* Represents the {@link Cooldown} style, allowing customization of the circle start, end, edge & text color.
33+
*
34+
* @since 1.2.5
35+
*/
36+
@Getter
37+
@Builder
38+
public final class CooldownStyle {
39+
40+
/**
41+
* Returns the cooldown circle start {@link Color}.
42+
*
43+
* @return the circle start color
44+
* @since 1.2.5
45+
*/
46+
@Nullable Color circleStartColor;
47+
48+
/**
49+
* Returns the cooldown circle end {@link Color}.
50+
*
51+
* @return the circle end color
52+
* @since 1.2.5
53+
*/
54+
@Nullable Color circleEndColor;
55+
56+
/**
57+
* Returns the cooldown circle edge {@link Color}.
58+
*
59+
* @return the circle edge color
60+
* @since 1.2.5
61+
*/
62+
@Nullable Color circleEdgeColor;
63+
64+
/**
65+
* Returns the cooldown text {@link Color}.
66+
*
67+
* @return the text color
68+
* @since 1.2.5
69+
*/
70+
@Nullable Color textColor;
71+
72+
}

common/src/main/java/com/lunarclient/apollo/module/cooldown/CooldownModuleImpl.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.lunarclient.apollo.network.NetworkTypes;
3030
import com.lunarclient.apollo.player.AbstractApolloPlayer;
3131
import com.lunarclient.apollo.recipients.Recipients;
32+
import java.awt.Color;
3233
import lombok.NonNull;
3334

3435
/**
@@ -40,12 +41,17 @@ public final class CooldownModuleImpl extends CooldownModule {
4041

4142
@Override
4243
public void displayCooldown(@NonNull Recipients recipients, @NonNull Cooldown cooldown) {
43-
DisplayCooldownMessage message = DisplayCooldownMessage.newBuilder()
44+
DisplayCooldownMessage.Builder builder = DisplayCooldownMessage.newBuilder()
4445
.setName(cooldown.getName())
4546
.setDuration(NetworkTypes.toProtobuf(cooldown.getDuration()))
46-
.setIcon(NetworkTypes.toProtobuf(cooldown.getIcon()))
47-
.build();
47+
.setIcon(NetworkTypes.toProtobuf(cooldown.getIcon()));
48+
49+
CooldownStyle style = cooldown.getStyle();
50+
if (style != null) {
51+
builder.setStyle(this.toProtobuf(style));
52+
}
4853

54+
DisplayCooldownMessage message = builder.build();
4955
recipients.forEach(player -> ((AbstractApolloPlayer) player).sendPacket(message));
5056
}
5157

@@ -69,4 +75,30 @@ public void resetCooldowns(@NonNull Recipients recipients) {
6975
recipients.forEach(player -> ((AbstractApolloPlayer) player).sendPacket(message));
7076
}
7177

78+
private com.lunarclient.apollo.cooldown.v1.CooldownStyle toProtobuf(CooldownStyle style) {
79+
com.lunarclient.apollo.cooldown.v1.CooldownStyle.Builder builder = com.lunarclient.apollo.cooldown.v1.CooldownStyle.newBuilder();
80+
81+
Color circleStartColor = style.getCircleStartColor();
82+
if (circleStartColor != null) {
83+
builder.setCircleStartColor(NetworkTypes.toProtobuf(circleStartColor));
84+
}
85+
86+
Color circleEndColor = style.getCircleEndColor();
87+
if (circleEndColor != null) {
88+
builder.setCircleEndColor(NetworkTypes.toProtobuf(circleEndColor));
89+
}
90+
91+
Color circleEdgeColor = style.getCircleEdgeColor();
92+
if (circleEdgeColor != null) {
93+
builder.setCircleEdgeColor(NetworkTypes.toProtobuf(circleEdgeColor));
94+
}
95+
96+
Color textColor = style.getTextColor();
97+
if (textColor != null) {
98+
builder.setTextColor(NetworkTypes.toProtobuf(textColor));
99+
}
100+
101+
return builder.build();
102+
}
103+
72104
}

docs/developers/lightweight/protobuf/getting-started.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Available fields for each message, including their types, are available on the B
2626
<dependency>
2727
<groupId>com.lunarclient</groupId>
2828
<artifactId>apollo-protos</artifactId>
29-
<version>0.0.6</version>
29+
<version>0.0.9</version>
3030
</dependency>
3131
</dependencies>
3232
```
@@ -41,7 +41,7 @@ Available fields for each message, including their types, are available on the B
4141
}
4242
4343
dependencies {
44-
api 'com.lunarclient:apollo-protos:0.0.6'
44+
api 'com.lunarclient:apollo-protos:0.0.9'
4545
}
4646
```
4747
</Tab>
@@ -55,7 +55,7 @@ Available fields for each message, including their types, are available on the B
5555
}
5656

5757
dependencies {
58-
api("com.lunarclient:apollo-protos:0.0.6")
58+
api("com.lunarclient:apollo-protos:0.0.9")
5959
}
6060
```
6161
</Tab>

docs/developers/modules/cooldown.mdx

Lines changed: 106 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,31 @@ public void displayCooldownItemExample(Player viewer) {
4545
}
4646
```
4747

48+
### Displaying a Cooldown with a custom style
49+
50+
```java
51+
public void displayCooldownWithStyleExample(Player viewer) {
52+
Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
53+
54+
apolloPlayerOpt.ifPresent(apolloPlayer -> {
55+
this.cooldownModule.displayCooldown(apolloPlayer, Cooldown.builder()
56+
.name("book-cooldown")
57+
.duration(Duration.ofSeconds(30))
58+
.icon(ItemStackIcon.builder()
59+
.itemName("BOOK")
60+
.build())
61+
.style(CooldownStyle.builder()
62+
.circleStartColor(ApolloColors.RED)
63+
.circleEndColor(ApolloColors.GREEN)
64+
.circleEdgeColor(ApolloColors.DARK_GRAY)
65+
.textColor(ApolloColors.LIGHT_PURPLE)
66+
.build())
67+
.build()
68+
);
69+
});
70+
}
71+
```
72+
4873
### Displaying a Cooldown with a resource
4974

5075
```java
@@ -56,8 +81,8 @@ public void displayCooldownResourceExample(Player viewer) {
5681
.name("lunar-cooldown")
5782
.duration(Duration.ofSeconds(15))
5883
.icon(SimpleResourceLocationIcon.builder()
59-
.resourceLocation("lunar:logo/logo-200x182.svg")
60-
.size(12)
84+
.resourceLocation("lunar:logo/logo-64x64.png")
85+
.size(24)
6186
.build()
6287
)
6388
.build()
@@ -74,6 +99,7 @@ public void removeCooldownExample(Player viewer) {
7499

75100
apolloPlayerOpt.ifPresent(apolloPlayer -> {
76101
this.cooldownModule.removeCooldown(apolloPlayer, "enderpearl-cooldown");
102+
this.cooldownModule.removeCooldown(apolloPlayer, "book-cooldown");
77103
this.cooldownModule.removeCooldown(apolloPlayer, "lunar-cooldown");
78104
});
79105
}
@@ -107,9 +133,43 @@ public void resetCooldownsExample(Player viewer) {
107133

108134
`.icon(SimpleResourceLocationIcon)` is how you display a custom texture icon. Read the [icons utilities page](/apollo/developers/utilities/icons) to learn more about icons.
109135
```java
110-
.icon(SimpleResourceLocationIcon.builder().resourceLocation("lunar:logo/logo-200x182.svg").size(12).build())
136+
.icon(SimpleResourceLocationIcon.builder().resourceLocation("lunar:logo/logo-64x64.png").size(24).build())
111137
```
112138

139+
`.style(CooldownStyle)` is how you customize the visual appearance of the cooldown circle and text. See the `CooldownStyle` section below for more.
140+
```java
141+
.style(CooldownStyle.builder()
142+
.circleStartColor(ApolloColors.RED)
143+
.circleEndColor(ApolloColors.GREEN)
144+
.circleEdgeColor(ApolloColors.DARK_GRAY)
145+
.textColor(ApolloColors.LIGHT_PURPLE)
146+
.build())
147+
```
148+
149+
### `CooldownStyle` Options
150+
151+
`.circleStartColor(java.awt.Color)` is the color displayed at the start of the cooldown circle animation. See the [colors page](/apollo/developers/utilities/colors) for more.
152+
```java
153+
.circleStartColor(ApolloColors.RED)
154+
```
155+
156+
`.circleEndColor(java.awt.Color)` is the color displayed at the end of the cooldown circle animation. See the [colors page](/apollo/developers/utilities/colors) for more.
157+
```java
158+
.circleEndColor(ApolloColors.GREEN)
159+
```
160+
161+
`.circleEdgeColor(java.awt.Color)` is the color of the circle's edge/border. See the [colors page](/apollo/developers/utilities/colors) for more.
162+
```java
163+
.circleEdgeColor(ApolloColors.DARK_GRAY)
164+
```
165+
166+
`.textColor(java.awt.Color)` is the color of the cooldown timer text rendered in the center of the circle. See the [colors page](/apollo/developers/utilities/colors) for more.
167+
```java
168+
.textColor(ApolloColors.LIGHT_PURPLE)
169+
```
170+
171+
All `CooldownStyle` fields are optional; any field left unset will fall back to the client's default value.
172+
113173
</Tab>
114174

115175
<Tab>
@@ -128,14 +188,34 @@ public void displayCooldownItemExample(Player viewer) {
128188
}
129189
```
130190

191+
**Displaying a Cooldown with a custom style**
192+
193+
```java
194+
public void displayCooldownWithStyleExample(Player viewer) {
195+
DisplayCooldownMessage message = DisplayCooldownMessage.newBuilder()
196+
.setName("book-cooldown")
197+
.setDuration(ProtobufUtil.createDurationProto(Duration.ofSeconds(30)))
198+
.setIcon(ProtobufUtil.createItemStackIconProto("BOOK", 0, 0))
199+
.setStyle(CooldownStyle.newBuilder()
200+
.setCircleStartColor(ProtobufUtil.createColorProto(new Color(255, 85, 85))) // ApolloColors.RED
201+
.setCircleEndColor(ProtobufUtil.createColorProto(new Color(85, 255, 85))) // ApolloColors.GREEN
202+
.setCircleEdgeColor(ProtobufUtil.createColorProto(new Color(85, 85, 85))) // ApolloColors.DAR_GRAY
203+
.setTextColor(ProtobufUtil.createColorProto(new Color(255, 85, 255))) // ApolloColors.LIGHT_PURPLE
204+
.build())
205+
.build();
206+
207+
ProtobufPacketUtil.sendPacket(viewer, message);
208+
}
209+
```
210+
131211
**Displaying a Cooldown with a resource**
132212

133213
```java
134214
public void displayCooldownResourceExample(Player viewer) {
135215
DisplayCooldownMessage message = DisplayCooldownMessage.newBuilder()
136216
.setName("lunar-cooldown")
137217
.setDuration(ProtobufUtil.createDurationProto(Duration.ofSeconds(15)))
138-
.setIcon(ProtobufUtil.createSimpleResourceLocationIconProto("lunar:logo/logo-200x182.svg", 12))
218+
.setIcon(ProtobufUtil.createSimpleResourceLocationIconProto("lunar:logo/logo-64x64.png", 24))
139219
.build();
140220

141221
ProtobufPacketUtil.sendPacket(viewer, message);
@@ -181,6 +261,27 @@ public void displayCooldownItemExample(Player viewer) {
181261
}
182262
```
183263

264+
**Displaying a Cooldown with a custom style**
265+
266+
```java
267+
public void displayCooldownWithStyleExample(Player viewer) {
268+
JsonObject message = new JsonObject();
269+
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.cooldown.v1.DisplayCooldownMessage");
270+
message.addProperty("name", "book-cooldown");
271+
message.addProperty("duration", JsonUtil.createDurationObject(Duration.ofSeconds(30)));
272+
message.add("icon", JsonUtil.createItemStackIconObject("BOOK", 0, 0));
273+
274+
JsonObject style = new JsonObject();
275+
style.add("circle_start_color", JsonUtil.createColorObject(new Color(255, 85, 85))); // ApolloColors.RED
276+
style.add("circle_end_color", JsonUtil.createColorObject(new Color(85, 255, 85))); // ApolloColors.GREEN
277+
style.add("circle_edge_color", JsonUtil.createColorObject(new Color(85, 85, 85))); // ApolloColors.DAR_GRAY
278+
style.add("text_color", JsonUtil.createColorObject(new Color(255, 85, 255))); // ApolloColors.LIGHT_PURPLE
279+
message.add("style", style);
280+
281+
JsonPacketUtil.sendPacket(viewer, message);
282+
}
283+
```
284+
184285
**Displaying a Cooldown with a resource**
185286

186287
```java
@@ -189,7 +290,7 @@ public void displayCooldownResourceExample(Player viewer) {
189290
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.cooldown.v1.DisplayCooldownMessage");
190291
message.addProperty("name", "lunar-cooldown");
191292
message.addProperty("duration", JsonUtil.createDurationObject(Duration.ofSeconds(15)));
192-
message.add("icon", JsonUtil.createSimpleResourceLocationIconObject("lunar:logo/logo-200x182.svg", 12));
293+
message.add("icon", JsonUtil.createSimpleResourceLocationIconObject("lunar:logo/logo-64x64.png", 24));
193294

194295
JsonPacketUtil.sendPacket(viewer, message);
195296
}

example/bukkit/api/src/main/java/com/lunarclient/apollo/example/api/listener/ApolloPlayerApiListener.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.lunarclient.apollo.event.player.ApolloRegisterPlayerEvent;
3030
import com.lunarclient.apollo.example.ApolloExamplePlugin;
3131
import com.lunarclient.apollo.example.api.module.TeamApiExample;
32+
import com.lunarclient.apollo.example.module.impl.CooldownExample;
3233
import com.lunarclient.apollo.player.ApolloPlayer;
3334
import org.bukkit.entity.Player;
3435

@@ -58,9 +59,13 @@ private void onApolloRegister(ApolloRegisterPlayerEvent event) {
5859

5960
this.example.getBeamExample().displayBeamExample(player);
6061
this.example.getBorderExample().displayBorderExample(player);
61-
this.example.getCooldownExample().displayCooldownItemExample(player);
6262
this.example.getNametagExample().overrideNametagExample(player);
6363
this.example.getWaypointExample().displayWaypointExample(player);
64+
65+
CooldownExample cooldownExample = this.example.getCooldownExample();
66+
cooldownExample.displayCooldownItemExample(player);
67+
cooldownExample.displayCooldownWithStyleExample(player);
68+
cooldownExample.displayCooldownResourceExample(player);
6469
}
6570

6671
}

0 commit comments

Comments
 (0)