Skip to content

Commit b9ec74c

Browse files
vectrixdevelopsTrentinTheKidItsNature
authored
Feature - Support SVG icons for cooldowns (#139)
* add svg example for cooldowns * add documentation for svg cooldown icons * Update cooldown example * Update cooldown docs * Minor cooldown example change --------- Co-authored-by: TrentinTheKid <25537885+TrentinTheKid@users.noreply.github.com> Co-authored-by: ItsNature <matej.bucaric@gmail.com>
1 parent a80f527 commit b9ec74c

File tree

5 files changed

+71
-13
lines changed

5 files changed

+71
-13
lines changed

bukkit-example/src/main/java/com/lunarclient/apollo/example/commands/CooldownCommand.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,20 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
4545
Player player = (Player) sender;
4646

4747
if (args.length != 1) {
48-
player.sendMessage("Usage: /cooldown <display|remove|reset>");
48+
player.sendMessage("Usage: /cooldown <displayItem|displayResource|remove|reset>");
4949
return true;
5050
}
5151

5252
switch (args[0].toLowerCase()) {
53-
case "display": {
54-
this.cooldownExample.displayCooldownExample(player);
55-
player.sendMessage("Displaying cooldown....");
53+
case "displayitem": {
54+
this.cooldownExample.displayCooldownItemExample(player);
55+
player.sendMessage("Displaying cooldown item....");
56+
break;
57+
}
58+
59+
case "displayresource": {
60+
this.cooldownExample.displayCooldownResourceExample(player);
61+
player.sendMessage("Displaying cooldown resource....");
5662
break;
5763
}
5864

@@ -69,7 +75,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
6975
}
7076

7177
default: {
72-
player.sendMessage("Usage: /cooldown <display|remove|reset>");
78+
player.sendMessage("Usage: /cooldown <displayItem|displayResource|remove|reset>");
7379
break;
7480
}
7581
}

bukkit-example/src/main/java/com/lunarclient/apollo/example/listeners/PlayerListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private void onApolloRegister(ApolloRegisterPlayerEvent event) {
4646

4747
this.plugin.getBeamExample().displayBeamExample(player);
4848
this.plugin.getBorderExample().displayBorderExample(player);
49-
this.plugin.getCooldownExample().displayCooldownExample(player);
49+
this.plugin.getCooldownExample().displayCooldownItemExample(player);
5050
this.plugin.getNametagExample().overrideNametagExample(player);
5151
this.plugin.getWaypointExample().displayWaypointExample(player);
5252
}

bukkit-example/src/main/java/com/lunarclient/apollo/example/modules/CooldownExample.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import com.lunarclient.apollo.Apollo;
2727
import com.lunarclient.apollo.common.icon.ItemStackIcon;
28+
import com.lunarclient.apollo.common.icon.SimpleResourceLocationIcon;
2829
import com.lunarclient.apollo.module.cooldown.Cooldown;
2930
import com.lunarclient.apollo.module.cooldown.CooldownModule;
3031
import com.lunarclient.apollo.player.ApolloPlayer;
@@ -36,7 +37,7 @@ public class CooldownExample {
3637

3738
private final CooldownModule cooldownModule = Apollo.getModuleManager().getModule(CooldownModule.class);
3839

39-
public void displayCooldownExample(Player viewer) {
40+
public void displayCooldownItemExample(Player viewer) {
4041
Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
4142

4243
apolloPlayerOpt.ifPresent(apolloPlayer -> {
@@ -52,9 +53,30 @@ public void displayCooldownExample(Player viewer) {
5253
});
5354
}
5455

56+
public void displayCooldownResourceExample(Player viewer) {
57+
Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
58+
59+
apolloPlayerOpt.ifPresent(apolloPlayer -> {
60+
this.cooldownModule.displayCooldown(apolloPlayer, Cooldown.builder()
61+
.name("lunar-cooldown")
62+
.duration(Duration.ofSeconds(15))
63+
.icon(SimpleResourceLocationIcon.builder()
64+
.resourceLocation("lunar:logo/logo-200x182.svg")
65+
.size(12)
66+
.build()
67+
)
68+
.build()
69+
);
70+
});
71+
}
72+
5573
public void removeCooldownExample(Player viewer) {
5674
Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
57-
apolloPlayerOpt.ifPresent(apolloPlayer -> this.cooldownModule.removeCooldown(apolloPlayer, "enderpearl-cooldown"));
75+
76+
apolloPlayerOpt.ifPresent(apolloPlayer -> {
77+
this.cooldownModule.removeCooldown(apolloPlayer, "enderpearl-cooldown");
78+
this.cooldownModule.removeCooldown(apolloPlayer, "lunar-cooldown");
79+
});
5880
}
5981

6082
public void resetCooldownsExample(Player viewer) {

docs/developers/modules/cooldown.mdx

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,32 @@ Apollo's cooldown module allows servers to interact with the Cooldown mod found
1313
### Sample Code
1414

1515
```java
16-
public void displayCooldownExample(Player viewer) {
16+
public void displayCooldownItemExample(Player viewer) {
1717
Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
1818

1919
apolloPlayerOpt.ifPresent(apolloPlayer -> {
2020
this.cooldownModule.displayCooldown(apolloPlayer, Cooldown.builder()
2121
.name("enderpearl-cooldown")
2222
.duration(Duration.ofSeconds(15))
2323
.icon(ItemStackIcon.builder()
24-
.itemId(Material.ENDER_PEARL.getId())
24+
.itemName("ENDER_PEARL")
25+
.build()
26+
)
27+
.build()
28+
);
29+
});
30+
}
31+
32+
public void displayCooldownResourceExample(Player viewer) {
33+
Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
34+
35+
apolloPlayerOpt.ifPresent(apolloPlayer -> {
36+
this.cooldownModule.displayCooldown(apolloPlayer, Cooldown.builder()
37+
.name("lunar-cooldown")
38+
.duration(Duration.ofSeconds(15))
39+
.icon(SimpleResourceLocationIcon.builder()
40+
.resourceLocation("lunar:logo/logo-200x182.svg")
41+
.size(12)
2542
.build()
2643
)
2744
.build()
@@ -42,17 +59,26 @@ public void displayCooldownExample(Player viewer) {
4259
.duration(Duration.ofSeconds(15))
4360
```
4461

45-
`.icon(itemStackIcon)` is how you display a custom icon. Read the [icons utilities page](/apollo/developers/utilities/icons) to learn more about icons.
62+
`.icon(itemStackIcon)` is how you display a custom item icon. Read the [icons utilities page](/apollo/developers/utilities/icons) to learn more about icons.
4663
```java
47-
.icon(ItemStackIcon.builder().itemId(Material.ENDER_PEARL.getId()).build())
64+
.icon(ItemStackIcon.builder().itemId("ENDER_PEARL").build())
65+
```
66+
67+
`.icon(SimpleResourceLocationIcon)` is how you display a custom texture icon. Read the [icons utilities page](/apollo/developers/utilities/icons) to learn more about icons.
68+
```java
69+
.icon(SimpleResourceLocationIcon.builder().resourceLocation("lunar:logo/logo-200x182.svg").size(12).build())
4870
```
4971

5072
### Removing a specific cooldown for a player
5173

5274
```java
5375
public void removeCooldownExample(Player viewer) {
5476
Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
55-
apolloPlayerOpt.ifPresent(apolloPlayer -> this.cooldownModule.removeCooldown(apolloPlayer, "enderpearl-cooldown"));
77+
78+
apolloPlayerOpt.ifPresent(apolloPlayer -> {
79+
this.cooldownModule.removeCooldown(apolloPlayer, "enderpearl-cooldown");
80+
this.cooldownModule.removeCooldown(apolloPlayer, "lunar-cooldown");
81+
});
5682
}
5783
```
5884

docs/developers/utilities/icons.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ public static ItemStackIcon itemStackNameIconExample() {
6565

6666
If you're using a custom resource pack and want to create an icon, you can use the `SimpleResourceLocation` builder.
6767

68+
<Callout type="info">
69+
The supplied resource location should point to a texture in the resource pack, or the path to an `svg` file in the resource pack.
70+
</Callout>
71+
6872
```java
6973
public final class SimpleResourceLocationIcon extends Icon {
7074

0 commit comments

Comments
 (0)