-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update with named arguments and documentation
- Loading branch information
Showing
4 changed files
with
279 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
.../main/java/net/kyori/adventure/text/minimessage/translation/NamedTranslationArgument.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* This file is part of adventure, licensed under the MIT License. | ||
* | ||
* Copyright (c) 2017-2025 KyoriPowered | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package net.kyori.adventure.text.minimessage.translation; | ||
|
||
import net.kyori.adventure.text.ComponentLike; | ||
import net.kyori.adventure.text.TranslatableComponent; | ||
import net.kyori.adventure.text.TranslationArgument; | ||
import net.kyori.adventure.text.TranslationArgumentLike; | ||
import net.kyori.adventure.text.minimessage.tag.TagPattern; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
/** | ||
* A {@link TranslationArgument} with an associated string name. | ||
* | ||
* <p>This is intended for use with {@link TranslatableComponent translatable components} | ||
* used with a {@link MiniMessageTranslator} instance to allow {@code <name>} tags.</p> | ||
* | ||
* @since 4.19.0 | ||
*/ | ||
public interface NamedTranslationArgument extends TranslationArgumentLike { | ||
/** | ||
* Create a named boolean argument. | ||
* | ||
* @param name the name | ||
* @param value the value | ||
* @return the named argument | ||
* @since 4.19.0 | ||
*/ | ||
static @NotNull NamedTranslationArgument bool(final @TagPattern @NotNull String name, final boolean value) { | ||
return argument(name, TranslationArgument.bool(value)); | ||
} | ||
|
||
/** | ||
* Create a named numeric argument. | ||
* | ||
* @param name the name | ||
* @param value the value | ||
* @return the named argument | ||
* @since 4.19.0 | ||
*/ | ||
static @NotNull NamedTranslationArgument numeric(final @TagPattern @NotNull String name, final @NotNull Number value) { | ||
return argument(name, TranslationArgument.numeric(value)); | ||
} | ||
|
||
/** | ||
* Create a named component argument. | ||
* | ||
* @param name the name | ||
* @param value the value | ||
* @return the named argument | ||
* @since 4.19.0 | ||
*/ | ||
static @NotNull NamedTranslationArgument component(final @TagPattern @NotNull String name, final @NotNull ComponentLike value) { | ||
return argument(name, TranslationArgument.component(value)); | ||
} | ||
|
||
/** | ||
* Create a named translation argument. | ||
* | ||
* @param name the name | ||
* @param argument the translation argument | ||
* @return the named argument | ||
* @since 4.19.0 | ||
*/ | ||
static @NotNull NamedTranslationArgument argument(final @TagPattern @NotNull String name, final @NotNull TranslationArgumentLike argument) { | ||
return argument(name, requireNonNull(argument, "argument").asTranslationArgument()); | ||
} | ||
|
||
/** | ||
* Create a named translation argument. | ||
* | ||
* @param name the name | ||
* @param argument the translation argument | ||
* @return the named argument | ||
* @since 4.19.0 | ||
*/ | ||
static @NotNull NamedTranslationArgument argument(final @TagPattern @NotNull String name, final @NotNull TranslationArgument argument) { | ||
return new NamedTranslationArgumentImpl(name, argument); | ||
} | ||
|
||
/** | ||
* The name of this translation argument. | ||
* | ||
* @return the name | ||
* @since 4.19.0 | ||
*/ | ||
@TagPattern @NotNull String name(); | ||
} |
55 changes: 55 additions & 0 deletions
55
...n/java/net/kyori/adventure/text/minimessage/translation/NamedTranslationArgumentImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* This file is part of adventure, licensed under the MIT License. | ||
* | ||
* Copyright (c) 2017-2025 KyoriPowered | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package net.kyori.adventure.text.minimessage.translation; | ||
|
||
import java.util.Objects; | ||
import net.kyori.adventure.text.TranslationArgument; | ||
import net.kyori.adventure.text.minimessage.internal.TagInternals; | ||
import net.kyori.adventure.text.minimessage.tag.TagPattern; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
final class NamedTranslationArgumentImpl implements NamedTranslationArgument { | ||
|
||
private final @TagPattern @NotNull String name; | ||
private final @NotNull TranslationArgument argument; | ||
|
||
NamedTranslationArgumentImpl(final @TagPattern @NotNull String name, final @NotNull TranslationArgument argument) { | ||
Objects.requireNonNull(name, "name"); | ||
Objects.requireNonNull(argument, "argument"); | ||
TagInternals.assertValidTagName(name); | ||
|
||
this.name = name; | ||
this.argument = argument; | ||
} | ||
|
||
@Override | ||
public @TagPattern @NotNull String name() { | ||
return this.name; | ||
} | ||
|
||
@Override | ||
public @NotNull TranslationArgument asTranslationArgument() { | ||
return this.argument; | ||
} | ||
} |