Skip to content

Commit

Permalink
WIP Add translatable support (Resolves #18)
Browse files Browse the repository at this point in the history
  • Loading branch information
Phoenix616 committed Jul 10, 2024
1 parent 029a0d0 commit dec56fc
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 89 deletions.
43 changes: 22 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,28 @@ as well as specify formatting, font and colors that way.


#### Advanced Syntax
Description | Syntax | More Info
-------------------|----------------------------------------|----
General syntax |` [Text](action=value) `|[ClickEvent.Action](https://github.com/KyoriPowered/adventure/blob/master/api/src/main/java/net/kyori/adventure/text/event/ClickEvent.java#L196-L222), [HoverEvent.Action](https://github.com/KyoriPowered/adventure/blob/master/api/src/main/java/net/kyori/adventure/text/event/HoverEvent.java#L311-L339)
Link |` [Text](open_url=https://example.com) `|
Color |` [Text](color=red) `| [Color names](https://minecraft.wiki/w/Formatting_codes)
RGB Hex Color |` [Text](color=#ff00ff) `| Full hexadecimal format
RGB Hex Color |` [Text](color=#f0f) `| Short format (equivalent to long one)
RGB Color Gradient |` [Text](color=#fff-#000) `| Gradient of two colors. (Supports all color forms)
RGB Color Gradient |` [Text](color=#fff-#333-#222) `| Gradient of three colors.
RGB Rainbow |` [Text](color=rainbow) `| An RGB rainbow.
Phased RGB Rainbow |` [Text](color=rainbow:50) `| An RGB rainbow with a specific phase.
Formatting |` [Text](format=underline,bold) `| Specify formatting
Disable Formatting |` [Text](format=!underline) `| Disable the specific formatting with a ! prefix
Font |` [Text](font=custom_font) `| Set a custom font from a resource pack
Run Command |` [Text](run_command=/command string) `| Run command on click
Suggest Command |` [Text](suggest_command=/command) `| Suggest a command on click
Simple Hover |` [Text](hover=Hover Text) `| Show hover text
Hover Text |` [Text](show_text=Hover Text) `| Show hover text
Hover Entity Info |` [Text](show_entity=uuid:pig Name) `| Show entity information.
Hover Item Info |` [Text](show_item=stone*2 nbt...) `| Show item information, additional information needs to be provided as a string of the nbt in json
Insertion |` [Text](insert=insert into input) `| Insert into input on shift click, can be combined with other events
Description | Syntax | More Info
--------------------|-----------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
General syntax | ` [Text](action=value) ` | [ClickEvent.Action](https://github.com/KyoriPowered/adventure/blob/master/api/src/main/java/net/kyori/adventure/text/event/ClickEvent.java#L196-L222), [HoverEvent.Action](https://github.com/KyoriPowered/adventure/blob/master/api/src/main/java/net/kyori/adventure/text/event/HoverEvent.java#L311-L339)
Link | ` [Text](open_url=https://example.com) ` |
Color | ` [Text](color=red) ` | [Color names](https://minecraft.wiki/w/Formatting_codes)
RGB Hex Color | ` [Text](color=#ff00ff) ` | Full hexadecimal format
RGB Hex Color | ` [Text](color=#f0f) ` | Short format (equivalent to long one)
RGB Color Gradient | ` [Text](color=#fff-#000) ` | Gradient of two colors. (Supports all color forms)
RGB Color Gradient | ` [Text](color=#fff-#333-#222) ` | Gradient of three colors.
RGB Rainbow | ` [Text](color=rainbow) ` | An RGB rainbow.
Phased RGB Rainbow | ` [Text](color=rainbow:50) ` | An RGB rainbow with a specific phase.
Formatting | ` [Text](format=underline,bold) ` | Specify formatting
Disable Formatting | ` [Text](format=!underline) ` | Disable the specific formatting with a ! prefix
Font | ` [Text](font=custom_font) ` | Set a custom font from a resource pack
Translatable | ` [fallback](translate=translation.key with={value1, value2}) ` | Translatable component with replacements
Run Command | ` [Text](run_command=/command string) ` | Run command on click
Suggest Command | ` [Text](suggest_command=/command) ` | Suggest a command on click
Simple Hover | ` [Text](hover=Hover Text) ` | Show hover text
Hover Text | ` [Text](show_text=Hover Text) ` | Show hover text
Hover Entity Info | ` [Text](show_entity=uuid:pig Name) ` | Show entity information.
Hover Item Info | ` [Text](show_item=stone*2 nbt...) ` | Show item information, additional information needs to be provided as a string of the nbt in json
Insertion | ` [Text](insert=insert into input) ` | Insert into input on shift click, can be combined with other events

All advanced settings can be chained/included in a event definition.
You can't however add multiple different colors or click and hover actions!
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>de.themoep</groupId>
<artifactId>minedown-adventure</artifactId>
<version>1.7.3-SNAPSHOT</version>
<version>1.7.4-SNAPSHOT</version>

<name>MineDown</name>

Expand Down Expand Up @@ -67,19 +67,19 @@
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-api</artifactId>
<version>4.9.1</version>
<version>4.13.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-gson</artifactId>
<version>4.9.1</version>
<version>4.13.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-serializer-legacy</artifactId>
<version>4.9.1</version>
<version>4.13.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
52 changes: 3 additions & 49 deletions src/main/java/de/themoep/minedown/adventure/MineDown.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,69 +23,23 @@
*/

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.TextDecoration;

import java.util.Map;

/**
* <h2>MineDown-adventure</h2>
* A MarkDown inspired markup for Minecraft chat components
* A MarkDown inspired markup for Minecraft chat components using the Adventure component library.
* <p>
* This lets you convert string messages into chat components by using a custom mark up syntax
* which is loosely based on MarkDown while still supporting legacy formatting codes.
*
* <table>
* <caption><strong> Inline Formatting </strong></caption>
* <tr><td> Color legacy </td><td><code> &amp;6Text </code></td><td> {@link TextColor} codes </td></tr>
* <tr><td> Color </td><td><code> &amp;gold&amp;Text </code></td><td> {@link TextColor} codes </td></tr>
* <tr><td> RGB Hex Color </td><td><code> &amp;ff00ff&amp;Text </code></td><td> Full hexadecimal format </td></tr>
* <tr><td> RGB Hex Color </td><td><code> &amp;f0f&amp;Text </code></td><td> Short format (equivalent to long one) </td></tr>
* <tr><td> Bold </td><td><code> **Text** </code></td></tr>
* <tr><td> Italic </td><td><code> ##Text## </code></td></tr>
* <tr><td> Underlined </td><td><code> __Text__ </code></td></tr>
* <tr><td> Strikethrough </td><td><code> ~~Text~~ </code></td></tr>
* <tr><td> Obfuscated </td><td><code> ??Text?? </code></td></tr>
* </table>
*
* <h3>Events</h3>
* You can define click and hover events with the commonly used MarkDown link syntax.
* <p>
* <table>
* <caption><strong> Simple Syntax </strong></caption>
* <tr><td> General syntax </td><td><code> [Text](text-color text-formatting... link hover text) </code></td></tr>
* <tr><td> Simple Link </td><td><code> [Text](https://example.com) </code></td></tr>
* <tr><td> Simple Command </td><td><code> [Text](/command to run) </code></td></tr>
* <tr><td> Link + Hover </td><td><code> [Text](https://example.com Hover Text) </code></td></tr>
* <tr><td> Text formatting + Link + Hover </td><td><code> [Text](blue underline https://example.com Hover Text) </code></td></tr>
* </table>
* <p>
* <table>
* <caption><strong> Advanced Syntax </strong></caption>
* <tr><td> General syntax </td><td><code> [Text](action=value) </code></td><td> {@link ClickEvent.Action}, {@link HoverEvent.Action} </td></tr>
* <tr><td> Link </td><td><code> [Text](open_url=https://example.com) </code></td></tr>
* <tr><td> Color </td><td><code> [Text](color=red) </code></td></tr>
* <tr><td> RGB Hex Color </td><td><code> [Text](color=#ff00ff) </code></td><td> Full hexadecimal format </td></tr>
* <tr><td> RGB Hex Color </td><td><code> [Text](color=#f0f) </code></td><td> Short format (equivalent to long one) </td></tr>
* <tr><td> Formatting </td><td><code> [Text](format=underline,bold) </code></td></tr>
* <tr><td> Font </td><td><code> [Text](format=underline,bold) </code></td></tr>
* <tr><td> Run Command </td><td><code> [Text](run_command=/command string) </code></td></tr>
* <tr><td> Suggest Command </td><td><code> [Text](suggest_command=/command) </code></td></tr>
* <tr><td> Simple Hover </td><td><code> [Text](hover=Hover Text) </code></td></tr>
* <tr><td> Hover Text </td><td><code> [Text](show_text=Hover Text) </code></td></tr>
* <tr><td> Hover Entity Info </td><td><code> [Text](show_entity=uuid:pig Name) </code></td></tr>
* <tr><td> Hover Item Info </td><td><code> [Text](show_item=stone*2 nbt...) </code></td></tr>
* </table>
* <p>
* All advanced settings can be chained/included in a event definition.
* You can't however add multiple different colors or click and hover actions!
*/
public class MineDown {
public static final String FONT_PREFIX = "font=";
public static final String COLOR_PREFIX = "color=";
public static final String FORMAT_PREFIX = "format=";
public static final String TRANSLATE_PREFIX = "translate=";
public static final String WITH_PREFIX = "with=";
public static final String HOVER_PREFIX = "hover=";
public static final String INSERTION_PREFIX = "insert=";

Expand Down
Loading

0 comments on commit dec56fc

Please sign in to comment.