Skip to content

Commit a712088

Browse files
committed
chore: format adventure code snippets and simplify particles
1 parent a525148 commit a712088

17 files changed

Lines changed: 65 additions & 63 deletions

File tree

src/config/paper/paper-world-defaults.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ misc:
10281028
in each implementation's respective documentation:
10291029
10301030
- Eigencraft: No official documentation available. However,
1031-
[theosib's comments](https://bugs.mojang.com/browse/MC-81098?focusedCommentId=420777#comment-420777)
1031+
[theosib's comments](https://mojira.dev/MC-81098?focusedCommentId=420777#comment-420777)
10321032
on the Mojira bug tracker give an overview of the Eigencraft implementation.
10331033
10341034
- [Alternate Current](https://github.com/SpaceWalkerRS/alternate-current/blob/main/README.md)
@@ -1139,7 +1139,7 @@ unsupported-settings:
11391139
default: "true"
11401140
description: >-
11411141
If set to false, the creation of invulnerable end crystals will be
1142-
allowed. Fixes [MC-108513](https://bugs.mojang.com/browse/MC-108513)
1142+
allowed. Fixes [MC-108513](https://mojira.dev/MC-108513)
11431143
ticking:
11441144
chunks:
11451145
default: "true"

src/content/docs/adventure/book.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ Books are composed of:
1515

1616
```java
1717
// Create and open a book about cats for the target audience
18-
public void openMyBook(final @NonNull Audience target) {
19-
Component bookTitle = Component.text("Encyclopedia of cats");
20-
Component bookAuthor = Component.text("kashike");
21-
Collection<Component> bookPages = Cats.getCatKnowledge();
18+
public void openMyBook(final Audience target) {
19+
final Component bookTitle = Component.text("Encyclopedia of cats");
20+
final Component bookAuthor = Component.text("kashike");
21+
final Collection<Component> bookPages = Cats.getCatKnowledge();
2222

23-
Book myBook = Book.book(bookTitle, bookAuthor, bookPages);
24-
target.openBook(myBook);
23+
final Book myBook = Book.book(bookTitle, bookAuthor, bookPages);
24+
target.openBook(myBook);
2525
}
2626
```
2727

src/content/docs/adventure/bossbar.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Boss Bars are composed of:
1818
```java
1919
private @Nullable BossBar activeBar;
2020

21-
public void showMyBossBar(final @NonNull Audience target) {
21+
public void showMyBossBar(final Audience target) {
2222
final Component name = Component.text("Awesome BossBar");
2323
// Creates a red boss bar which has no progress and no notches
2424
final BossBar emptyBar = BossBar.bossBar(name, 0, BossBar.Color.RED, BossBar.Overlay.PROGRESS);
@@ -34,7 +34,7 @@ public void showMyBossBar(final @NonNull Audience target) {
3434
this.activeBar = fullBar;
3535
}
3636

37-
public void hideActiveBossBar(final @NonNull Audience target) {
37+
public void hideActiveBossBar(final Audience target) {
3838
target.hideBossBar(this.activeBar);
3939
this.activeBar = null;
4040
}

src/content/docs/adventure/faq.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ PlaceholderAPI placeholders are not supported in MiniMessage. However, you can e
4343
* @param player the player
4444
* @return the tag resolver
4545
*/
46-
public @NotNull TagResolver papiTag(final @NotNull Player player) {
46+
public TagResolver papiTag(final Player player) {
4747
return TagResolver.resolver("papi", (argumentQueue, context) -> {
4848
// Get the string placeholder that they want to use.
4949
final String papiPlaceholder = argumentQueue.popOr("papi tag requires an argument").value();

src/content/docs/adventure/localization.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,30 +64,31 @@ Below is an example of how one might implement a custom `Translator`.
6464
public class MyTranslator implements Translator {
6565

6666
@Override
67-
public @NotNull Key name() {
67+
public Key name() {
6868
// Every translator has a name which is used to identify this specific translator instance.
6969
return Key.key("mynamespace:mykey");
7070
}
7171

7272
@Override
73-
public @Nullable MessageFormat translate(final @NotNull String key, final @NotNull Locale locale) {
73+
public @Nullable MessageFormat translate(final String key, final Locale locale) {
7474
// You could retrieve a string from a properties file, a config file, or some other system.
75-
// An an example, we will hard-code a check for a specific key here.
75+
// As an example, we will hard-code a check for a specific key here.
7676
if (key.equals("mytranslation.key") && locale == Locale.US) {
77-
return new MessageFormat("Hello %s!", locale);
77+
return new MessageFormat("Hello {0}!", locale);
7878
} else {
7979
// If you only want to use component translation, you can override this method and always return `null`.
8080
return null;
8181
}
8282
}
8383

8484
@Override
85-
public @Nullable Component translate(@NotNull TranslatableComponent component, @NotNull Locale locale) {
85+
public @Nullable Component translate(final TranslatableComponent component, final Locale locale) {
8686
// As above, we will hardcode a check here, but you should be reading this from elsewhere.
87-
if (key.equals("mytranslation.colorful") && locale == Locale.US) {
87+
if (component.key().equals("mytranslation.colorful") && locale == Locale.US) {
8888
return Component.text("Hello, ", NamedTextColor.GREEN)
89-
.append(component.arguments().get(0).color(NamedTextColor.RED))
90-
.append(component.children()); // Always make sure to copy the children over!
89+
.append(component.arguments().stream().map(it -> it.asComponent().color(NamedTextColor.RED)).toList())
90+
.append(component.children()) // Always make sure to copy the children over!
91+
.applyFallbackStyle(component.style());
9192
} else {
9293
return null;
9394
}
@@ -107,10 +108,10 @@ An example of how to use a translation store is below.
107108
```java
108109
// As above, every translator needs an identifying name!
109110
// Could also use TranslationStore#component(Key) to work with components instead.
110-
final TranslationStore myStore = TranslationStore.messageFormat(Key.key("mynamespace:mykey"));
111+
final TranslationStore.StringBased<MessageFormat> myStore = TranslationStore.messageFormat(Key.key("mynamespace:mykey"));
111112

112113
// You can add translations one-by-one, or in bulk. Consult the Javadocs for a full list of methods.
113-
myStore.register("mytranslation.key", Locale.US, new MessageFormat("Hello %s!", Locale.US));
114+
myStore.register("mytranslation.key", Locale.US, new MessageFormat("Hello {0}!", Locale.US));
114115

115116
// You can then register this to the global translator so the translations are available there!
116117
GlobalTranslator.translator().addSource(myStore);

src/content/docs/adventure/migration/bungeecord-chat-api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ becomes this Adventure equivalent:
9898

9999
```java
100100
Component.text()
101-
.append(Component.text("hello", NamedTextColor.GOLD)
101+
.append(Component.text("hello", NamedTextColor.GOLD))
102102
.append(Component.text(" world"))
103103
.build()
104104
```
@@ -118,7 +118,7 @@ becomes
118118
```java
119119
Style style = Style.style(NamedTextColor.GOLD, TextDecoration.BOLD);
120120
Component.text()
121-
.append(Component.text("hello", style)
121+
.append(Component.text("hello", style))
122122
.append(Component.text(" world", style))
123123
.build()
124124
```

src/content/docs/adventure/minimessage/api.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ MiniMessage allows you to both serialize components into MiniMessage strings and
3232
Here's a short example to try things out:
3333

3434
```java
35-
Audience player = ...;
36-
MiniMessage mm = MiniMessage.miniMessage();
35+
final Audience player = ...;
36+
final MiniMessage mm = MiniMessage.miniMessage();
3737

38-
Component parsed = mm.deserialize("Hello <rainbow>world</rainbow>, isn't <underlined>MiniMessage</underlined> fun?");
38+
final Component parsed = mm.deserialize("Hello <rainbow>world</rainbow>, isn't <underlined>MiniMessage</underlined> fun?");
3939

4040
player.sendMessage(parsed);
4141
```
@@ -85,7 +85,7 @@ final MiniMessage myCustomMiniMessageInstance = builder.build();
8585
To make customizing MiniMessage easier, we provide a Builder. The specific methods on the builder are explained in the javadoc.
8686

8787
```java
88-
MiniMessage minimessage = MiniMessage.builder()
88+
final MiniMessage mm = MiniMessage.builder()
8989
.tags(TagResolver.builder()
9090
.resolver(StandardTags.color())
9191
.resolver(StandardTags.decorations())
@@ -129,7 +129,7 @@ The builder for `MiniMessage` allows providing a custom tag resolver rather than
129129
MiniMessage also provides convenience methods to do that:
130130

131131
```java
132-
MiniMessage serializer = MiniMessage.builder()
132+
final MiniMessage serializer = MiniMessage.builder()
133133
.tags(TagResolver.builder()
134134
.resolver(StandardTags.color())
135135
.build()

src/content/docs/adventure/minimessage/translator.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,18 @@ public class MyMiniMessageTranslator extends MiniMessageTranslator {
3030
}
3131

3232
@Override
33-
public @Nullable String getMiniMessageString(final @NotNull String key, final @NotNull Locale locale) {
33+
public Key name() {
34+
// Every translator has a name which is used to identify this specific translator instance.
35+
return Key.key("mynamespace:mykey");
36+
}
37+
38+
@Override
39+
public @Nullable String getMiniMessageString(final String key, final Locale locale) {
3440
// Creating a custom MiniMessage translator is as simple as overriding this one method.
3541
// All you need to do is return a MiniMessage string for the provided key and locale.
3642
// In this example we will hardcode this, but you could pull it from a resource bundle, a properties file, a config file or something else entirely.
3743
if (key.equals("mykey") && locale == Locale.US) {
38-
return "<red>Hello, <name>! Today is <day_of_week>."
44+
return "<red>Hello, <name>! Today is <day_of_week>.";
3945
} else {
4046
// Returning null "ignores" this translation.
4147
return null;

src/content/docs/adventure/platform/bukkit.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public class MyPlugin extends JavaPlugin {
3636

3737
private BukkitAudiences adventure;
3838

39-
@NonNull
4039
public BukkitAudiences adventure() {
4140
if (this.adventure == null) {
4241
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");

src/content/docs/adventure/platform/bungeecord.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public class MyPlugin extends Plugin {
3838

3939
private BungeeAudiences adventure;
4040

41-
@NonNull
4241
public BungeeAudiences adventure() {
4342
if (this.adventure == null) {
4443
throw new IllegalStateException("Cannot retrieve audience provider while plugin is not enabled");

0 commit comments

Comments
 (0)