-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow entry placeholders to have parameters
- Loading branch information
Showing
22 changed files
with
823 additions
and
130 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
documentation/docs/develop/02-extensions/04-entries/placeholder.mdx
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,44 @@ | ||
import CodeSnippet from "@site/src/components/CodeSnippet"; | ||
|
||
# Placeholder | ||
Entries can expose a placeholder. | ||
The placeholders can be used by users or other plugins with the PlaceholderAPI. | ||
|
||
:::danger | ||
Placeholder is an additional interface for an existing entry. It cannot be used on its own. | ||
::: | ||
|
||
## Basic Usage | ||
To just expose a single placeholder, extend your entry with `PlaceholderEntry`: | ||
|
||
<CodeSnippet tag="simple_placeholder_entry" json={require("../../snippets.json")} /> | ||
|
||
This placeholder can be used with `%typewriter_<entry id>%` and will return `Hello <player name>!` | ||
|
||
## Sub Placeholders | ||
Besides just having a primary placeholder, entries can also have sub placeholders. | ||
These can be literal strings which needs to be matched: | ||
|
||
<CodeSnippet tag="literal_placeholder_entry" json={require("../../snippets.json")} /> | ||
|
||
Where the placeholder can be used in the following ways: | ||
|
||
| Placeholder | Result | | ||
|------------|---------| | ||
| `%typewriter_<entry id>%` | `Standard text` | | ||
| `%typewriter_<entry id>:greet%` | `Hello, <player name>!` | | ||
| `%typewriter_<entry id>:greet:enthusiastic%` | `HEY HOW IS YOUR DAY, <player name>!` | | ||
|
||
But is can also have variables: | ||
|
||
<CodeSnippet tag="string_placeholder_entry" json={require("../../snippets.json")} /> | ||
|
||
Where the placeholder can be used in the following ways: | ||
|
||
| Placeholder | Result | | ||
|------------|---------| | ||
| `%typewriter_<entry id>%` | `%typewriter_<entry id>%` | | ||
| `%typewriter_<entry id>:bob%` | `Hello, bob!` | | ||
| `%typewriter_<entry id>:alice%` | `Hello, alice!` | | ||
|
||
Notice how the default placeholder no longer works, because we don't have a supplier for it anymore. |
41 changes: 41 additions & 0 deletions
41
documentation/docs/develop/02-extensions/07-api-changes/0.7.mdx
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,41 @@ | ||
--- | ||
title: 0.7.X API Changes | ||
--- | ||
|
||
import Tabs from "@theme/Tabs"; | ||
import TabItem from "@theme/TabItem"; | ||
|
||
# All API changes to 0.7.X | ||
|
||
The v0.7.X release contains the new Dynamic variable. | ||
To learn how to use them, see [Dynamic Variables](/develop/extensions/entries/static/variable). | ||
|
||
## PlaceholderEntry Changes | ||
|
||
<Tabs> | ||
<TabItem value="old" label="Old"> | ||
```kotlin showLineNumbers | ||
override fun display(player: Player?): String? { | ||
return "Hello, ${player?.name ?: "World"}!" | ||
} | ||
``` | ||
</TabItem> | ||
<TabItem value="new" label="New" default> | ||
```kotlin showLineNumbers | ||
override fun parser(): PlaceholderParser = placeholderParser { | ||
supply { player -> | ||
"Hello, ${player?.name ?: "World"}!" | ||
} | ||
} | ||
``` | ||
</TabItem> | ||
</Tabs> | ||
|
||
The placeholder now returns a parser instead of directly parsing. | ||
This allows for more complex placeholders to be created. | ||
With sub placeholders, for example. | ||
|
||
For example the `TimedFact` returns the fact value by default for fact `%typewriter_<entry id>%`. | ||
But if you want the time when the fact will expire you can use `%typewriter_<entry id>:time:expires:relative%` | ||
Where the `:time:expires:relative` is a sub placeholder. | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
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
20 changes: 20 additions & 0 deletions
20
engine/engine-core/src/main/kotlin/com/typewritermc/core/utils/DurationFormat.kt
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,20 @@ | ||
package com.typewritermc.core.utils | ||
|
||
import kotlin.time.Duration | ||
import kotlin.time.Duration.Companion.days | ||
import kotlin.time.Duration.Companion.hours | ||
import kotlin.time.Duration.Companion.minutes | ||
|
||
fun Duration.formatCompact(): String { | ||
val days = this.inWholeDays | ||
val hours = (this - days.days).inWholeHours | ||
val minutes = (this - days.days - hours.hours).inWholeMinutes | ||
val seconds = (this - days.days - hours.hours - minutes.minutes).inWholeSeconds | ||
|
||
return buildString { | ||
if (days > 0) append("${days}d ") | ||
if (hours > 0) append("${hours}h ") | ||
if (minutes > 0) append("${minutes}m ") | ||
if (seconds > 0 || this.isEmpty()) append("${seconds}s") | ||
}.trim() | ||
} |
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
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
Oops, something went wrong.