Skip to content

Commit ab4da9c

Browse files
committed
Added ForwardingAudience support guide
resolves #11
1 parent e7a981c commit ab4da9c

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
title: ForwardingAudience Support
3+
sidebar_label: 'ForwardingAudience Support'
4+
sidebar_position: 7
5+
---
6+
7+
There are some cases where it is necessary to use Audience Wrappers, especially in the case of cross-platform plugins.
8+
9+
For this reason, MiniPlaceholders supports Audience wrappers that implement the ForwardingAudience.Single interface.
10+
11+
```java
12+
public record AudienceWrapper(Player player) implements ForwardingAudience.Single {
13+
@Override
14+
public Audience audience() {
15+
return this.player;
16+
}
17+
}
18+
```
19+
20+
For example, here we create a wrapper that contains a player. In a real situation, this class would have much more logic, but for this example, we will create a basic wrapper.
21+
22+
Having created the wrapper, we can also use it to obtain placeholders for the player contained within the wrapper.
23+
24+
```java
25+
final Player player = event.getPlayer();
26+
final AudienceWrapper wrapperAudience = new AudienceWrapper(player);
27+
final TagResolver resolver = MiniPlaceholders.audiencePlaceholders();
28+
final Component parsedMessage = MiniMessage.miniMessage().deserialize("Player Name: <player_name>", wrapperAudience, resolver);
29+
```
30+
31+
Note that this will only work if the expansion that will provide the placeholders correctly declares its preferred audience type.
32+
33+
34+
```java
35+
Expansion.builder("test")
36+
.audiencePlaceholder(Player.class, "placeholder", (player, ctx, queue) -> {
37+
return Tag.preProcessParsed(player.getName());
38+
});
39+
```
40+
41+
To use this feature, you can refer to plugins that already use this feature continuously, such as [CarbonChat](https://github.com/Hexaoxide/Carbon).

0 commit comments

Comments
 (0)