Showing with 3,625 additions and 344 deletions.
  1. +1 −1 build.gradle
  2. +8 −6 docs/user/mod-placeholders.md
  3. +188 −0 docs/user/quicktext.md
  4. +5 −0 docs/user/text-format.md
  5. +5 −5 gradle.properties
  6. +1 −1 gradle/wrapper/gradle-wrapper.properties
  7. +1 −1 src/main/java/eu/pb4/placeholders/api/PlaceholderContext.java
  8. +35 −28 src/main/java/eu/pb4/placeholders/api/Placeholders.java
  9. +6 −0 src/main/java/eu/pb4/placeholders/api/TextParserUtils.java
  10. +140 −0 src/main/java/eu/pb4/placeholders/api/arguments/SimpleArguments.java
  11. +230 −0 src/main/java/eu/pb4/placeholders/api/arguments/StringArgs.java
  12. +36 −0 src/main/java/eu/pb4/placeholders/api/node/DynamicTextNode.java
  13. +20 −2 src/main/java/eu/pb4/placeholders/api/node/TranslatedNode.java
  14. +9 −8 src/main/java/eu/pb4/placeholders/api/node/parent/BoldNode.java
  15. +4 −5 src/main/java/eu/pb4/placeholders/api/node/parent/ClickActionNode.java
  16. +4 −5 src/main/java/eu/pb4/placeholders/api/node/parent/ColorNode.java
  17. +4 −5 src/main/java/eu/pb4/placeholders/api/node/parent/FontNode.java
  18. +4 −3 src/main/java/eu/pb4/placeholders/api/node/parent/FormattingNode.java
  19. +68 −11 src/main/java/eu/pb4/placeholders/api/node/parent/GradientNode.java
  20. +6 −6 src/main/java/eu/pb4/placeholders/api/node/parent/HoverNode.java
  21. +4 −5 src/main/java/eu/pb4/placeholders/api/node/parent/InsertNode.java
  22. +7 −5 src/main/java/eu/pb4/placeholders/api/node/parent/ItalicNode.java
  23. +6 −5 src/main/java/eu/pb4/placeholders/api/node/parent/ObfuscatedNode.java
  24. +6 −1 src/main/java/eu/pb4/placeholders/api/node/parent/ParentNode.java
  25. +24 −0 src/main/java/eu/pb4/placeholders/api/node/parent/SimpleStylingNode.java
  26. +6 −5 src/main/java/eu/pb4/placeholders/api/node/parent/StrikethroughNode.java
  27. +1 −6 src/main/java/eu/pb4/placeholders/api/node/parent/StyledNode.java
  28. +6 −5 src/main/java/eu/pb4/placeholders/api/node/parent/UnderlinedNode.java
  29. +10 −12 src/main/java/eu/pb4/placeholders/api/parsers/LegacyFormattingParser.java
  30. +1 −12 src/main/java/eu/pb4/placeholders/api/parsers/MarkdownLiteParserV1.java
  31. +4 −0 src/main/java/eu/pb4/placeholders/api/parsers/NodeParser.java
  32. +254 −0 src/main/java/eu/pb4/placeholders/api/parsers/ParserBuilder.java
  33. +6 −12 src/main/java/eu/pb4/placeholders/api/parsers/PatternPlaceholderParser.java
  34. +401 −0 src/main/java/eu/pb4/placeholders/api/parsers/TagLikeParser.java
  35. +5 −0 src/main/java/eu/pb4/placeholders/api/parsers/TagLikeWrapper.java
  36. +89 −0 src/main/java/eu/pb4/placeholders/api/parsers/TagParser.java
  37. +50 −4 src/main/java/eu/pb4/placeholders/api/parsers/TextParserV1.java
  38. +116 −0 src/main/java/eu/pb4/placeholders/api/parsers/format/BaseFormat.java
  39. +63 −0 src/main/java/eu/pb4/placeholders/api/parsers/format/MultiCharacterFormat.java
  40. +42 −0 src/main/java/eu/pb4/placeholders/api/parsers/format/SingleCharacterFormat.java
  41. +24 −0 src/main/java/eu/pb4/placeholders/api/parsers/tag/NodeCreator.java
  42. +30 −0 src/main/java/eu/pb4/placeholders/api/parsers/tag/SimpleTags.java
  43. +103 −0 src/main/java/eu/pb4/placeholders/api/parsers/tag/TagRegistry.java
  44. +47 −0 src/main/java/eu/pb4/placeholders/api/parsers/tag/TextTag.java
  45. +1 −51 src/main/java/eu/pb4/placeholders/impl/GeneralUtils.java
  46. +138 −0 src/main/java/eu/pb4/placeholders/impl/StringArgOps.java
  47. +57 −0 src/main/java/eu/pb4/placeholders/impl/color/HSV.java
  48. +76 −0 src/main/java/eu/pb4/placeholders/impl/color/OkLab.java
  49. +32 −0 src/main/java/eu/pb4/placeholders/impl/color/OkLch.java
  50. +1 −1 src/main/java/eu/pb4/placeholders/impl/placeholder/PlaceholderNode.java
  51. +11 −0 src/main/java/eu/pb4/placeholders/impl/placeholder/builtin/ServerPlaceholders.java
  52. +591 −0 src/main/java/eu/pb4/placeholders/impl/textparser/BuiltinTags.java
  53. +34 −1 src/main/java/eu/pb4/placeholders/impl/textparser/MergedParser.java
  54. +56 −0 src/main/java/eu/pb4/placeholders/impl/textparser/MultiTagLikeParser.java
  55. +32 −0 src/main/java/eu/pb4/placeholders/impl/textparser/SingleTagLikeParser.java
  56. +2 −43 src/main/java/eu/pb4/placeholders/impl/textparser/TextParserImpl.java
  57. +2 −2 src/main/java/eu/pb4/placeholders/impl/textparser/{TextTags.java → TextTagsV1.java}
  58. +50 −0 src/main/java/eu/pb4/placeholders/impl/textparser/providers/LegacyProvider.java
  59. +44 −0 src/main/java/eu/pb4/placeholders/impl/textparser/providers/LenientFormat.java
  60. +70 −0 src/main/java/eu/pb4/placeholders/impl/textparser/providers/LenientProvider.java
  61. +61 −0 src/main/java/eu/pb4/placeholders/impl/textparser/providers/ModernProvider.java
  62. +87 −0 src/main/java/eu/pb4/placeholders/impl/textparser/tagreg/SimpleTagRegistry.java
  63. +61 −0 src/main/java/eu/pb4/placeholders/impl/textparser/tagreg/WrappingTagRegistry.java
  64. +139 −87 src/testmod/java/eu/pb4/placeholderstest/TestMod.java
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.12-SNAPSHOT'
id 'fabric-loom' version '1.4.+'
id 'maven-publish'
id "com.modrinth.minotaur" version "2.+"
}
Expand Down
14 changes: 8 additions & 6 deletions docs/user/mod-placeholders.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ These placeholders are provided by other mods. Some are build in directly, while
### [AfkPlus](https://modrinth.com/mod/afkplus)

- `%afkplus:afk%` - Returns a configurable "[AFK]" tag if the player is marked as AFK.
- `%afkplus:name`/`%afkplus:display_name` - Returns a configurable replacement for `%player:displayname%` if the player is marked as AFK.
This allows for backport formatting, and it can fully support LuckPerms Prefixes, and other mods. By default it returns the standard
- `%afkplus:name%`/`%afkplus:display_name%` - Returns a configurable replacement for `%player:displayname%` if the player is marked as AFK.
This allows for backport formatting, and it can fully support LuckPerms Prefixes, and other mods. By default, it returns the standard
`%player:displayname%` when not AFK, which is also configurable.
- `%afkplus:duration` - Returns the (HH:mm:SS_ss) duration since a player went AFK, or nothing.
Configurable in a more human readable format, ie. (5 minutes, 3 seconds).
- `%afkplus:time` - Returns the time (yyyy-MM-dd_HH.mm.ss) since a player went AFK, or nothing.
- `%afkplus:reason` - Returns the reason why a player went AFK, or nothing.
- `%afkplus:duration%` - Returns the (HH-mm-SS.ss) duration since a player went AFK, or nothing.
Configurable in a more human-readable format, i.e., 5 minutes, 3 seconds.
- `%afkplus:time%` - Returns the time (yyyy-MM-dd_HH.mm.ss) since a player went AFK, or nothing.
- `%afkplus:reason%` - Returns the reason why a player went AFK, or nothing.
- `%afkplus:invulnerable%` - Returns a basic tag to display the status if a player is marked as "invulnerable" using the "disableDamage"
features. It is also used internally under the default "[AFK]" tag method, with "[AFK:I]", for example.

### [Get Off My Lawn ReServed](https://pb4.eu/#get-off-my-lawn)

Expand Down
188 changes: 188 additions & 0 deletions docs/user/quicktext.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
# QuickText Format (Beta)

!!! warn inline end

Having issues with formatted arguments not working? It's possible the version of mod you use uses
[Simplified Text Format](/user/text-format/) instead! Check it's documentation for more information!


It's a simple, but flexible, tag based text format designed for modern Minecraft.
It was created to allow quick and readable way of formatting Minecraft Text Components
while still providing all of its functionality as opposed for legacy &/§ formatting
used by bukkit and bukkit-based plugins.

## Structure

Formatting is build on concept of tags, comparable to html.

Most of them come in pairs of a starting (`#!xml <tag>`) and closing one (`#!xml </tag>` for closing last tag of selected type or `#!xml <‍/‍>` for last opened one.
While closing ones are technically optional, without them formatting will continue until end of
an input text or special `#!xml </*>` tag. Some tags support arguments, which are defined
after the name in ordered inline fashion (for example `#!xml <color #FF3333>`) or as key-value pair (for example `#!xml <hover value:'Hello!'>`).
You are allowed to mix inline and key-value defined arguments (in `KEY:VALUE` format). In that case, any key defined argument will be skipped from being read as ordered one.
Arguments spaces are required to be wrapped in a `'`, `"` or ``` symbols, with starting and ending symbols matching
(for example `#!xml <hover show_text '<red>Hello!'>...`, `#!xml <hover type:show_text value:'<red>Hello!'>...`).
If you want to use character used for wrapping, you can prefix it with backslash (for example as `\'`) or type it twice).

In case you want to type `#!xml <tag>` as plain text, you need to prefix it with `\ ` symbol .

???+ example

- `#!xml <color #11dddd>%player displayname%</color> <dark_gray>»</dark_gray> <color #cccccc>${message}`
- `#!xml <red>Hello <blue>world</blue>!</red>`
- `#!xml <rainbow>Some colors for you`

There are also few self-contained tags, that don't require closing ones. They can also take arguments
in the same way to previous ones.

Few examples:
- `#!xml <lang 'item.minecraft.diamond'>`
- `#!xml <key 'key.jump'>`
## List of available tags

Here is list of all default tags available. Other mods can add new or limit usage
of existing ones, so not every might work in yours case.

### Colors

!!! note inline end

This tag should be closed.

By default, there are multiple tags representing colors. They use their vanilla name or (additional aliases).

The current list includes `#!xml <yellow>`, `#!xml <dark_blue>`, `#!xml <dark_purple>`, `#!xml <gold>`, `#!xml <red>`, `#!xml <aqua>`,
`#!xml <gray>`, `#!xml <light_purple>`, `#!xml <white>`, `#!xml <dark_gray>`, `#!xml <green>`, `#!xml <dark_green>`, `#!xml <blue>`,
`#!xml <dark_aqua>`, `#!xml <dark_green>`, `#!xml <black>`

There is also a universal `#!xml <color [VALUE]>`, `#!xml <color value:[VALUE]>`, `#!xml <c [VALUE]>` and `#!xml <c value:[VALUE]>` tags, in which you can replace `[VALUE]` with vanilla color name
or an rgb color starting with `#` (for example `#!xml <color #AABBCC>`)

### Decorations

!!! note inline end

This tag should be closed.

These tags allow decorating text, they are quite simple.

- `#!xml <strikethrough>`/`#!xml <st>` - Makes the text strikethrough,
- `#!xml <underline>`/`#!xml <underlined>` - Underlines the text,
- `#!xml <italic>`/`#!xml <i>` - Makes the text italic,
- `#!xml <obfuscated>`/`#!xml <obf>` - Obfuscates the text (matrix effect),
- `#!xml <bold>`/`#!xml <b>` - Makes the text bold,

### Click events

!!! note inline end

This tag should be closed.

!!! danger

They should be however limited to admin usage only, as they can do harm if accessible by normal players.
Click events allows making text more interactive.
Tag definitions: `#!xml <click type:[TYPE] value:'[VALUE]'>`, `#!xml <click [TYPE] '[VALUE]'>` or direct shortcut tags.

There are few available actions:

- `#!xml <click open_url value '[VALUE]'>`/`#!xml <open_url '[VALUE]'>`/`#!xml <url '[VALUE]'>` - Opens the provided url
- `#!xml <click run_command '[VALUE]'>`/`#!xml <run_cmd '[VALUE]'>` - Runs a command as the player
- `#!xml <click suggest_command '[VALUE]'>`/`#!xml <suggest_command '[VALUE]'>`/`#!xml <cmd '[VALUE]'>` - Suggests a command to the player
- `#!xml <click copy_to_clipboard '[VALUE]'>`/`#!xml <copy_to_clipboard '[VALUE]'>`/`#!xml <copy '[VALUE]'>` - Copies text to the clipboard
- `#!xml <click change_page '[VALUE]'>`/`#!xml <change_page '[VALUE]'>`/`#!xml <page '[VALUE]'>` - Changes the page in a book

`[VALUE]` needs to be replaced with targeted value, for example `gamemode creative`

### Hover

Hover tag allows adding simple hover on text. It can be used to display additional information.

!!! note inline end

This tag should be closed.

- `#!xml <hover show_text '[VALUE]'>`/`#!xml <hover '[VALUE]'>` - Adds a simple text hover (`[VALUE]` uses the same formatting as rest)
- `#!xml <hover show_item '[VALUE]'>` - Adds a simple ItemStack hover (`'[VALUE]'` is item in sNBT format)
- `#!xml <hover show_entity [type] [UUID] 'Display Name'>` - Adds an entity hover.
(The colon (` `) in the entity type needs to be replaced with `\ `.
For example, `#!xml <hover show_entity minecraft\ bee [UUID] 'Display Name'>`)

### Fonts

!!! note inline end

This tag should be closed.

This tag allows you to change font to any build in one or one provided by resource pack.

You can use it by simply adding `#!xml <font '[VALUE]'>`, where `'[VALUE]'` is just a font name.
Minecraft has 3 build-in fonts `default`, `uniform` and `alt`.

### Inserting

!!! note inline end

This tag should be closed.

This tag creates a clickable text, that inserts its value at the end of player's chat message.

You can use it by writing `#!xml <insert '[VALUE]'>`, where `'[VALUE]'` inserted text (should be wrapped in `'`).

### Translations

!!! note inline end

This tag is self containing, so it doesn't contain a closing tag.

Translations tag allows you to insert a text from a lang file (including ones parsed on servers by some mods).

You use it with `#!xml <lang [key] [optional arg 1] [optional arg 1] ...>` or `#!xml <lang key:[key] fallback:[fallback] [optional arg 1] [optional arg 1] ...>`
where `[key]` is a translation key, optional/key only `[fallback]` is used for keys missing their client side translations
and `[optional arg X]` are optional, fully formatted arguments you can pass.

### Control keys

!!! question inline end "Control Keys"

You can find a list of control keys on the [Minecraft Wiki](https //minecraft.wiki/w/Controls#Configurable_controls)

!!! note inline end

This tag is self containing, so it doesn't contain a closing tag.

This tag allows you to add information about player control keys, with respecting of theirs configuration.

You can use it with `#!xml <keybind '[VALUE]'>` or `#!xml <keybind value:'[VALUE]'>`, where `'[VALUE]'` is a control key used.

### Gradients

This tag allows you to add gradients to the text. However, it has multiple limitation that can
block its usage. Currently, you can't use dynamic values (translations, control keys, placeholders, etc)
within them, as they require static text.

There 2 types of gradients:
- `#!xml <gradient (type:[type]) [color 1] [color 2] ...>`/`#!xml <gr (type:[type]) [color 1] [color 2] ...>` - I can take multiple colors to move between them
smoothly. You can replace the optional `(type:[type])` with `type:oklab` (default), `type:hvs` or `type:hard` to change how thge gradient is handled
- `#!xml <hard_gradient [color 1] [color 2] ...>`/`#!xml <hgr [color 1] [color 2] ...>` - I can take multiple colors to move between them
without mixing them.
- `#!xml <rainbow [frequency] [saturation] [offset]>`/`<rainbow f:[frequency] s:[saturation] o:[offset]>`/`#!xml <rb [...]>` - It's simple rainbow gradient. All arguments are
optional (`#!xml <ranbow>` is still valid) and they take numbers between 0 and 1 (`0.3` for example)

### Clear (2.1.3+)

!!! note inline end

This tag should be closed.

This tag allows you to clear any formatting within this tag, without leaving any visible tags. It also
works with placeholders, which gives a bit more flexibility.

This tag can work without arguments making it clear all formatting or with them limiting clearing to selected types.

Examples:
- `#!xml <clear>` - Removes all formatting, leaving only text.
- `#!xml <clear hover>` - Removes all hovers.
- `#!xml <clear hover color>` - Removes all hovers and colors.

Supported arguments `color`, `bold`, `italic`, `strikethrough`, `underline`, `hover`, `click`,:`insertion`, `font`, `all`.
5 changes: 5 additions & 0 deletions docs/user/text-format.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Simplified Text Format

!!! warn inline end

Having issues with formatted arguments not working? It's possible the version of mod you use uses
[QuickText](/user/quicktext/) instead! Check it's documentation for more information!

It's a simple, string format inspired by formats like HTML or MiniMessage.
It was created to allow quick and readable way of formatting Minecraft Text Components
while still providing all of its functionality as opposed for legacy &/§ formatting
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.20.3-rc1
yarn_mappings=1.20.3-rc1+build.1
loader_version=0.14.24
minecraft_version=1.20.4
yarn_mappings=1.20.4+build.1
loader_version=0.15.0

#Fabric api
fabric_version=0.90.9+1.20.3
fabric_version=0.91.1+1.20.4

# Mod Properties
mod_version = 2.3.0+1.20.3
mod_version = 2.4.0-pre.1+1.20.4
maven_group = eu.pb4
archives_base_name = placeholder-api

2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec2f;
import net.minecraft.util.math.Vec3d;
import org.jetbrains.annotations.Nullable;

import javax.annotation.Nullable;
import java.util.function.Supplier;

public record PlaceholderContext(MinecraftServer server,
Expand Down
Loading