Skip to content

Commit

Permalink
Add more markdown examples
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsNature committed Sep 13, 2024
1 parent 4474747 commit 7d0eeb2
Show file tree
Hide file tree
Showing 17 changed files with 445 additions and 57 deletions.
175 changes: 157 additions & 18 deletions docs/developers/modules/cooldown.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Tab, Tabs } from 'nextra-theme-docs'

# Cooldown Module

## Overview
Expand All @@ -17,6 +19,13 @@ Apollo's cooldown module allows servers to interact with the Cooldown mod found
## Integration

### Sample Code
Explore each integration by cycling through each tab, to find the best fit for your requirements and needs.

<Tabs items={['Apollo API', 'apollo-protos library', 'Manual JSON Object Construction']}>

<Tab>

### Displaying a Cooldown with an item

```java
public void displayCooldownItemExample(Player viewer) {
Expand All @@ -34,7 +43,11 @@ public void displayCooldownItemExample(Player viewer) {
);
});
}
```

### Displaying a Cooldown with a resource

```java
public void displayCooldownResourceExample(Player viewer) {
Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());

Expand All @@ -53,46 +66,172 @@ public void displayCooldownResourceExample(Player viewer) {
}
```

### `Cooldown` Options
### Removing a Cooldown

`.name(String)` should include a unique identifier for the each cooldown.
```java
.name("enderpearl-cooldown")
public void removeCooldownExample(Player viewer) {
Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());

apolloPlayerOpt.ifPresent(apolloPlayer -> {
this.cooldownModule.removeCooldown(apolloPlayer, "enderpearl-cooldown");
this.cooldownModule.removeCooldown(apolloPlayer, "lunar-cooldown");
});
}
```

`.duration(java.time.Duration)` the duration the cooldown should last for. See the [java.time.Duration Javadocs](https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html) for more.
### Resetting all Cooldowns

```java
.duration(Duration.ofSeconds(15))
public void resetCooldownsExample(Player viewer) {
Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
apolloPlayerOpt.ifPresent(this.cooldownModule::resetCooldowns);
}
```

`.icon(itemStackIcon)` is how you display a custom item icon. Read the [icons utilities page](/apollo/developers/utilities/icons) to learn more about icons.
</Tab>

<Tab>

### Displaying a Cooldown with an item

```java
.icon(ItemStackIcon.builder().itemId("ENDER_PEARL").build())
public void displayCooldownItemExample(Player viewer) {
DisplayCooldownMessage message = DisplayCooldownMessage.newBuilder()
.setName("enderpearl-cooldown")
.setDuration(ProtobufUtil.createDurationProto(Duration.ofSeconds(15)))
.setIcon(ProtobufUtil.createIconProto(ItemStackIcon.builder()
.itemName("ENDER_PEARL")
.build()))
.build();

ProtobufPacketUtil.sendPacket(viewer, message);
}
```

`.icon(SimpleResourceLocationIcon)` is how you display a custom texture icon. Read the [icons utilities page](/apollo/developers/utilities/icons) to learn more about icons.
### Displaying a Cooldown with a resource

```java
.icon(SimpleResourceLocationIcon.builder().resourceLocation("lunar:logo/logo-200x182.svg").size(12).build())
public void displayCooldownResourceExample(Player viewer) {
DisplayCooldownMessage message = DisplayCooldownMessage.newBuilder()
.setName("lunar-cooldown")
.setDuration(ProtobufUtil.createDurationProto(Duration.ofSeconds(15)))
.setIcon(ProtobufUtil.createIconProto(SimpleResourceLocationIcon.builder()
.resourceLocation("lunar:logo/logo-200x182.svg")
.size(12)
.build()))
.build();

ProtobufPacketUtil.sendPacket(viewer, message);
}
```

### Removing a specific cooldown for a player
### Removing a Cooldown

```java
public void removeCooldownExample(Player viewer) {
Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
RemoveCooldownMessage enderpearlMessage = RemoveCooldownMessage.newBuilder()
.setName("enderpearl-cooldown")
.build();

apolloPlayerOpt.ifPresent(apolloPlayer -> {
this.cooldownModule.removeCooldown(apolloPlayer, "enderpearl-cooldown");
this.cooldownModule.removeCooldown(apolloPlayer, "lunar-cooldown");
});
ProtobufPacketUtil.sendPacket(viewer, enderpearlMessage);
}
```

### Resetting all cooldowns for a player
### Resetting all Cooldowns

```java
public void resetCooldownsExample(Player viewer) {
Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
apolloPlayerOpt.ifPresent(this.cooldownModule::resetCooldowns);
ResetCooldownsMessage message = ResetCooldownsMessage.getDefaultInstance();
ProtobufPacketUtil.sendPacket(viewer, message);
}
```

</Tab>

<Tab>

### Displaying a Cooldown with an item

```java
public void displayCooldownItemExample(Player viewer) {
JsonObject message = new JsonObject();
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.cooldown.v1.DisplayCooldownMessage");
message.addProperty("name", "enderpearl-cooldown");
message.addProperty("duration", JsonUtil.createDurationObject(Duration.ofSeconds(15)));
message.add("icon", JsonUtil.createIconObject(
ItemStackIcon.builder()
.itemName("ENDER_PEARL")
.build())
);

JsonPacketUtil.sendPacket(viewer, message);
}
```

### Displaying a Cooldown with a resource

```java
public void displayCooldownResourceExample(Player viewer) {
JsonObject message = new JsonObject();
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.cooldown.v1.DisplayCooldownMessage");
message.addProperty("name", "lunar-cooldown");
message.addProperty("duration", JsonUtil.createDurationObject(Duration.ofSeconds(15)));
message.add("icon", JsonUtil.createIconObject(
SimpleResourceLocationIcon.builder()
.resourceLocation("lunar:logo/logo-200x182.svg")
.size(12)
.build())
);

JsonPacketUtil.sendPacket(viewer, message);
}
```

### Removing a Cooldown

```java
public void removeCooldownExample(Player viewer) {
JsonObject message = new JsonObject();
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.cooldown.v1.RemoveCooldownMessage");
message.addProperty("name", "enderpearl-cooldown");

JsonPacketUtil.sendPacket(viewer, message);
}
```

### Resetting all Cooldowns

```java
public void resetCooldownsExample(Player viewer) {
JsonObject message = new JsonObject();
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.cooldown.v1.ResetCooldownsMessage");

JsonPacketUtil.sendPacket(viewer, message);
}
```

</Tab>

</Tabs>

### `Cooldown` Options

`.name(String)` should include a unique identifier for the each cooldown.
```java
.name("enderpearl-cooldown")
```

`.duration(java.time.Duration)` the duration the cooldown should last for. See the [java.time.Duration Javadocs](https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html) for more.
```java
.duration(Duration.ofSeconds(15))
```

`.icon(itemStackIcon)` is how you display a custom item icon. Read the [icons utilities page](/apollo/developers/utilities/icons) to learn more about icons.
```java
.icon(ItemStackIcon.builder().itemId("ENDER_PEARL").build())
```

`.icon(SimpleResourceLocationIcon)` is how you display a custom texture icon. Read the [icons utilities page](/apollo/developers/utilities/icons) to learn more about icons.
```java
.icon(SimpleResourceLocationIcon.builder().resourceLocation("lunar:logo/logo-200x182.svg").size(12).build())
```
Loading

1 comment on commit 7d0eeb2

@LunarClientBot
Copy link
Collaborator

@LunarClientBot LunarClientBot commented on 7d0eeb2 Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📄 Documentation Deployment

Status:✅ Completed
Environment:preview
URL:https://3caced52.lunarclient-dev.pages.dev

Please sign in to comment.