Compare commits

..

8 Commits

Author SHA1 Message Date
PiggyPiglet
8673466ad0 fixed typo and added example 2026-02-02 16:18:24 +08:00
Andre601
39769506c2 Update Info 2026-01-31 15:04:08 +01:00
Andre_601
b3825b5c45 Merge pull request #1160 from PlaceholderAPI/feat/wiki-add-hytale-docs
Add Hytale-related docs
2026-01-31 13:32:26 +01:00
Funnycube
431e0234c2 Update PlaceholderAPI version requirements in docs 2026-01-31 21:12:53 +11:00
Funnycube
589135a9f4 Fix grammar in PlaceholderExpansion documentation
Corrected minor grammatical errors in the documentation.
2026-01-31 21:10:35 +11:00
Andre601
a32c6e4df0 Add Hytale-related docs 2026-01-26 13:52:39 +01:00
Andre601
bd6928414d [Wiki] Add info on new Component support 2026-01-18 18:00:56 +01:00
Andre_601
27cee54915 Merge pull request #1156 from PlaceholderAPI/wiki-updated-domains
Updated Domains!
2026-01-13 03:52:34 +01:00
3 changed files with 273 additions and 50 deletions

View File

@@ -2,20 +2,27 @@ document$.subscribe(async => {
const api_code = document.querySelectorAll('[data-md-component="api-version"]'); const api_code = document.querySelectorAll('[data-md-component="api-version"]');
function loadAPIInfo(data) { function loadAPIInfo(data) {
const version = data["version"]; const mcVersion = data["mcVersion"];
const versionToken = "{version}"; const hyVersion = data["hyVersion"];
const mcVersionToken = "{papiVersion}";
const hyVersionToken = "{papiHytaleVersion}"
for (const codeBlock of api_code) { for (const codeBlock of api_code) {
codeBlock.innerHTML = codeBlock.innerHTML.replace(new RegExp(versionToken, 'g'), version); codeBlock.innerHTML = codeBlock.innerHTML
.replace(new RegExp(mcVersionToken, 'g'), mcVersion)
.replace(new RegExp(hyVersionToken, 'g'), hyVersion);
} }
} }
async function fetchAPIInfo() { async function fetchAPIInfo() {
const release = await fetch("https://repo.extendedclip.com/api/maven/latest/version/releases/me/clip/placeholderapi").then(_ => _.json()); const [mcRelease, hyRelease] = await Promise.all([
fetch("https://repo.extendedclip.com/api/maven/latest/version/releases/me/clip/placeholderapi").then(_ => _.json()),
console.log(release) fetch("https://repo.helpch.at/api/maven/latest/version/releases/at/helpch/placeholderapi-hytale").then(_ => _.json())
])
const data = { const data = {
"version": release.version "mcVersion": mcRelease.version,
"hyVersion": hyRelease.version
} }
__md_set("__api_tag", data, sessionStorage); __md_set("__api_tag", data, sessionStorage);
@@ -24,7 +31,7 @@ document$.subscribe(async => {
if(location.href.includes("/developers/using-placeholderapi")) { if(location.href.includes("/developers/using-placeholderapi")) {
const cachedApi = __md_get("__api_tag", sessionStorage); const cachedApi = __md_get("__api_tag", sessionStorage);
if ((cachedApi != null) && (cachedApi["version"])) { if ((cachedApi != null) && (cachedApi["mcVersion"])) {
loadAPIInfo(cachedApi); loadAPIInfo(cachedApi);
} else { } else {
fetchAPIInfo(); fetchAPIInfo();

View File

@@ -4,6 +4,13 @@ description: Comprehensive guide on how to create a PlaceholderExpansion for oth
# Creating a PlaceholderExpansion # Creating a PlaceholderExpansion
/// warning | Important
These pages cover the creation of a PlaceholderExpansion for both Spigot/Paper-based and Hytale Servers!
Unless mentioned otherwise the provided code examples function for both platform types.
Please always check code blocks for :material-plus-circle: Icons with additional info!
///
This page will cover how you can create your own [`PlaceholderExpansion`][placeholderexpansion] which you can either integrate into your own plugin (Recommended) or [upload to the eCloud](expansion-cloud.md). This page will cover how you can create your own [`PlaceholderExpansion`][placeholderexpansion] which you can either integrate into your own plugin (Recommended) or [upload to the eCloud](expansion-cloud.md).
It's worth noting that PlaceholderAPI relies on expansions being installed. PlaceholderAPI only acts as the core replacing utility while the expansions allow other plugins to use any installed placeholder in their own messages. It's worth noting that PlaceholderAPI relies on expansions being installed. PlaceholderAPI only acts as the core replacing utility while the expansions allow other plugins to use any installed placeholder in their own messages.
@@ -74,6 +81,11 @@ public class SomeExpansion extends PlaceholderExpansion {
public String onPlaceholderRequest(Player player, @NotNull String params) { public String onPlaceholderRequest(Player player, @NotNull String params) {
// (5) // (5)
} }
@Override
public String onPlaceholderRequest(PlayerRef player, @NotNull String params) {
// (6)
}
} }
``` ```
@@ -108,6 +120,16 @@ public class SomeExpansion extends PlaceholderExpansion {
- `player` - Nullable Player instance to parse placeholders against. - `player` - Nullable Player instance to parse placeholders against.
- `params` - Non-null String representing the part of the placeholder after the first `_` and before the closing `%` (or `}` for bracket placeholders). - `params` - Non-null String representing the part of the placeholder after the first `_` and before the closing `%` (or `}` for bracket placeholders).
6. **Note:** Only exists for the Hytale Version of PlaceholderAPI!
Called by PlaceholderAPI through `onPlaceholderRequest(PlayerRef, String)` to have placeholder values parsed.
When `null` is returned will PlaceholderAPI treat it as invalid placeholder and return it unchanged.
**Parameters:**
- `player` - PlayerRef instance to parse placeholders against.
- `params` - Non-null String representing the part of the placeholder after the first `_` and before the closing `%` (or `}` for bracket placeholders).
/// note /// note
Overriding `onRequest(OfflinePlayer, String)` or `onPlaceholderRequest(Player, String)` is not required if you [create relational placeholders](#making-a-relational-expansion). Overriding `onRequest(OfflinePlayer, String)` or `onPlaceholderRequest(Player, String)` is not required if you [create relational placeholders](#making-a-relational-expansion).
/// ///
@@ -133,16 +155,18 @@ You are also required to override and set `persist()` to `true`. This tells Plac
attrs: { id: full-example-internal } attrs: { id: full-example-internal }
type: example type: example
//// note | //// note | Important Notes
Please see the [Basic PlaceholderExpansion Structure](#basic-placeholderexpansion-structure) section for an explanation of all common methods in this example. - Please see the [Basic PlaceholderExpansion Structure](#basic-placeholderexpansion-structure) section for an explanation of all common methods in this example.
- The below example is for a Spigot/Paper-based setup.
For a Hytale server, replace `me.clip` imports with `at.helpch` and replace `OfflinePlayer` with `PlayerRef` (Including the import).
Tab the :material-plus-circle: icons in the code block below for additional information. Tab the :material-plus-circle: icons in the code block below for additional information.
//// ////
```java { .annotate title="SomeExpansion.java" } ```java { .annotate title="SomeExpansion.java" }
package at.helpch.placeholderapi.example.expansion; package com.example.plugin.expansion;
import at.helpch.placeholderapi.example.SomePlugin; import com.example.plugin.SomePlugin;
import me.clip.placeholderapi.expansion.PlaceholderExpansion; import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -206,19 +230,20 @@ public class SomeExpansion extends PlaceholderExpansion {
6. Example of accessing data of the plugin's `config.yml` file. 6. Example of accessing data of the plugin's `config.yml` file.
7. Reaching this means that an invalid params String was given, so we return `null` to tell PlaceholderAPI that the placeholder was invalid. 7. Reaching this means that an invalid params String was given, so we return `null` to tell PlaceholderAPI that the placeholder was invalid.
/// ///
### Register your Expansion ### Register your Expansion
Due to the PlaceholderExpansion being internal, PlaceholderAPI does not load it automatically, we'll need to do it manually. Due to the PlaceholderExpansion being internal, PlaceholderAPI does not load it automatically, we'll need to do it manually.
This is being done by creating a new instance of your PlaceholderExpansion class and calling the `register()` method of it. This is being done by creating a new instance of your PlaceholderExpansion class and calling the `register()` method of it:
Here is a quick example: /// tab | Spigot, Paper, ...
```java { .annotate title="SomePlugin.java" } ```java { .annotate title="SomePlugin.java" }
package at.helpch.placeholderapi.example; package com.example.plugin;
import at.helpch.placeholderapi.example.expansion.SomeExpansion; import com.example.plugin.expansion.SomeExpansion;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@@ -238,6 +263,37 @@ public class SomePlugin extends JavaPlugin {
2. This registers our expansion in PlaceholderAPI. It also gives the Plugin class as dependency injection to the Expansion class, so that we can use it. 2. This registers our expansion in PlaceholderAPI. It also gives the Plugin class as dependency injection to the Expansion class, so that we can use it.
///
/// tab | Hytale
```java { .annotate title="SomePlugin.java" }
package com.example.plugin;
import com.example.plugin.expansion.SomeExpansion;
import com.hypixel.hytale.server.core.plugin.JavaPlugin;
import com.hypixel.hytale.server.core.plugin.JavaPluginInit;
import com.hypixel.hytale.common.plugin.PluginIdentifier;
import com.hypixel.hytale.server.core.HytaleServer;
public class SomePlugin extends JavaPlugin {
public SomePlugin(JavaPluginInit init) {
super(init)
}
@Override
protected void start() {
if (HytaleServer.get().getPluginManager().getPlugin(PluginIdentifier.fromString("HelpChat:PlaceholderAPI")) != null) {
new SomeExpansion(this).register();
}
}
}
```
///
---- ----
## Making an External Expansion ## Making an External Expansion
@@ -257,8 +313,10 @@ Downsides include a more tedious setup in terms of checking for a required plugi
attrs: { id: full-example-external-no-dependency } attrs: { id: full-example-external-no-dependency }
type: example type: example
//// note | //// note | Important Notes
Please see the [Basic PlaceholderExpansion Structure](#basic-placeholderexpansion-structure) section for an explanation of all common methods in this example. - Please see the [Basic PlaceholderExpansion Structure](#basic-placeholderexpansion-structure) section for an explanation of all common methods in this example.
- The below example is for a Spigot/Paper-based setup.
For a Hytale server, replace `me.clip` imports with `at.helpch` and replace `OfflinePlayer` with `PlayerRef` (Including the import).
Tab the :material-plus-circle: icons in the code block below for additional information. Tab the :material-plus-circle: icons in the code block below for additional information.
//// ////
@@ -266,7 +324,7 @@ Tab the :material-plus-circle: icons in the code block below for additional info
This is an example expansion without any plugin dependency. This is an example expansion without any plugin dependency.
```java { .annotate title="SomeExpansion.java" } ```java { .annotate title="SomeExpansion.java" }
package at.helpch.placeholderapi.example.expansion; package com.example.expansion;
import me.clip.placeholderapi.expansion.PlaceholderExpansion; import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
@@ -314,8 +372,10 @@ public class SomeExpansion extends PlaceholderExpansion {
attrs: { id: full-example-external-dependency } attrs: { id: full-example-external-dependency }
type: example type: example
//// note | //// note | Important Notes
Please see the [Basic PlaceholderExpansion Structure](#basic-placeholderexpansion-structure) section for an explanation of all common methods in this example. - Please see the [Basic PlaceholderExpansion Structure](#basic-placeholderexpansion-structure) section for an explanation of all common methods in this example.
- The below example is for a Spigot/Paper-based setup.
For a Hytale server, replace `me.clip` imports with `at.helpch` and replace `OfflinePlayer` with `PlayerRef` (Including the import).
Tab the :material-plus-circle: icons in the code block below for additional information. Tab the :material-plus-circle: icons in the code block below for additional information.
//// ////
@@ -323,9 +383,9 @@ Tab the :material-plus-circle: icons in the code block below for additional info
This is an example expansion with a plugin dependency. This is an example expansion with a plugin dependency.
```java { .annotate title="SomeExpansion.java" } ```java { .annotate title="SomeExpansion.java" }
package at.helpch.placeholderapi.example.expansion; package com.example.expansion;
import at.helpch.placeholderapi.example.SomePlugin; import com.example.plugin.SomePlugin;
import me.clip.placeholderapi.expansion.PlaceholderExpansion; import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
@@ -383,7 +443,9 @@ public class SomeExpansion extends PlaceholderExpansion {
2. The name of the plugin this expansion depends on. 2. The name of the plugin this expansion depends on.
It is recommended to set this, as it would result in PlaceholderAPI reporting any missing plugin for your expansion. It is recommended to set this, as it would result in PlaceholderAPI reporting any missing plugin for your expansion.
3. This does two things: 3. **Note:** This only works on a Spigot/Paper-based server. A equivalent for Hytale servers is not yet known.
This does two things:
1. It sets the `plugin` instance to `SomePlugin` using Bukkit's PluginManager to retrieve a JavaPlugin instance that is cast to `SomePlugin`. 1. It sets the `plugin` instance to `SomePlugin` using Bukkit's PluginManager to retrieve a JavaPlugin instance that is cast to `SomePlugin`.
2. It checks if the retrieved instance is not null. If it is will this result in `canRegister()` returning false, resulting in PlaceholderAPI not loading our expansion. 2. It checks if the retrieved instance is not null. If it is will this result in `canRegister()` returning false, resulting in PlaceholderAPI not loading our expansion.
@@ -399,8 +461,9 @@ public class SomeExpansion extends PlaceholderExpansion {
## Making a relational Expansion ## Making a relational Expansion
/// note /// note | Notes
Relational Placeholders always start with `rel_` to properly identify them. This means that if you make a relational placeholder called `friends_is_friend` would the full placeholder be `%rel_friends_is_friend%`. - Relational Placeholders always start with `rel_` to properly identify them. This means that if you make a relational placeholder called `friends_is_friend` would the full placeholder be `%rel_friends_is_friend%`.
- For Hytale, replace any mention of `Player` with `PlayerRef` and update any Imports in the code to `at.helpch` and related Hytale ones.
/// ///
Relational PlaceholderExpansions are special in that they take two players as input, allowing you to give outputs based on their relation to each other. Relational PlaceholderExpansions are special in that they take two players as input, allowing you to give outputs based on their relation to each other.

View File

@@ -6,33 +6,43 @@ description: Guide on how to use PlaceholderAPI in your own plugin.
This page is about using PlaceholderAPI in your own plugin, to either let other plugins use your plugin, or just use placeholders from other plugins in your own. This page is about using PlaceholderAPI in your own plugin, to either let other plugins use your plugin, or just use placeholders from other plugins in your own.
Please note, that the examples in this page are only available for **PlaceholderAPI 2.10.0 or higher**! Please note, that the examples in this page are only available for **PlaceholderAPI 2.10.0 (1.0.0 for Hytale version) or newer**!
## First steps ## First steps
Before you can actually make use of PlaceholderAPI, you first have to import it into your project. ### Add PlaceholderAPI to your Project
Use the below code example matching your dependency manager.
/// tab | :simple-apachemaven: Maven Before you can actually make use of PlaceholderAPI, you first have to import it into your project.
Use the below code example matching your project type and dependency manager.
/// tab | Minecraft (Spigot, Paper, ...)
//// tab | :simple-apachemaven: Maven
```{ .xml title="pom.xml" data-md-component="api-version" } ```{ .xml title="pom.xml" data-md-component="api-version" }
<repositories> <repositories>
<repository> <repository>
<id>placeholderapi</id> <id>placeholderapi</id>
<url>https://repo.extendedclip.com/releases/</url> <url>https://repo.helpch.at/releases/</url>
</repository> </repository>
</repositories> </repositories>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>me.clip</groupId> <groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId> <artifactId>placeholderapi</artifactId>
<version>{version}</version> <version>{papiVersion}</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- Optional: Component support on Paper Servers (Since 2.12.0) -->
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi-paper</artifactId>
<version>{papiVersion}</version>
<scope>provided</scope>
</dependencies> </dependencies>
``` ```
/// ////
/// tab | :simple-gradle: Gradle //// tab | :simple-gradle: Gradle
```{ .groovy title="build.gradle" data-md-component="api-version" } ```{ .groovy title="build.gradle" data-md-component="api-version" }
repositories { repositories {
maven { maven {
@@ -41,15 +51,68 @@ repositories {
} }
dependencies { dependencies {
compileOnly 'me.clip:placeholderapi:{version}' compileOnly 'me.clip:placeholderapi:{papiVersion}'
// Optional: Component support on Paper Servers (Since 2.12.0)
compileOnly 'me.clip:placeholderapi-paper:{papiVersion}'
} }
``` ```
////
/// ///
/// details | What is `{version}`? /// tab | Hytale
//// tab | :simple-apachemaven: Maven
```{ .xml title="pom.xml" data-md-component="api-version" }
<repositories>
<repository>
<id>hytale</id>
<url>https://repo.codemc.io/repository/hytale/</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.helpch.at/releases/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<!-- Replace {hytaleVersion} with the version you need -->
<groupId>com.hypixel.hytale</groupId>
<artifactId>Server</artifactId>
<version>{hytaleVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>at.helpch</groupId>
<artifactId>placeholderapi-hytale</artifactId>
<version>{papiHytaleVersion}</version>
<scope>provided</scope>
</dependency>
</dependencies>
```
////
//// tab | :simple-gradle: Gradle
```{ .groovy title="build.gradle" data-md-component="api-version" }
repositories {
maven {
url = 'https://repo.codemc.io/repository/hytale/'
url = 'https://repo.helpch.at/releases/'
}
}
dependencies {
// Replace {hytaleVersion} with the version you need.
compileOnly 'com.hypixel.hytale:Server:{hytaleVersion}'
compileOnly 'at.helpch:placeholderapi-hytale:{papiHytaleVersion}'
}
```
////
///
/// details | What is `{papiVersion}`/`{papiHytaleVersion}`?
type: question type: question
Using Javascript, `{version}` is replaced with the latest available API version of PlaceholderAPI. Using Javascript, `{papiVersion}` and `{papiHytaleVersion}` is replaced with the latest available API version of PlaceholderAPI for Minecraft and Hytale respectively.
Should you see the placeholder as-is does it mean that you either block Javascript, or that the version couldn't be obtained in time during page load. Should you see the placeholder as-is does it mean that you either block Javascript, or that the version couldn't be obtained in time during page load.
You can always find the latest version matching the API version on the [releases tab](https://github.com/PlaceholderAPI/PlaceholderAPI/releases) of the GitHub Repository. You can always find the latest version matching the API version on the [releases tab](https://github.com/PlaceholderAPI/PlaceholderAPI/releases) of the GitHub Repository.
@@ -71,7 +134,7 @@ Tab the :material-plus-circle: icons in the code block below for additional info
name: ExamplePlugin name: ExamplePlugin
version: 1.0 version: 1.0
author: author author: author
main: your.main.path.Here main: com.example.plugin.ExamplePlugin
softdepend: ["PlaceholderAPI"] # (1) softdepend: ["PlaceholderAPI"] # (1)
``` ```
@@ -89,7 +152,7 @@ Tab the :material-plus-circle: icons in the code block below for additional info
name: ExamplePlugin name: ExamplePlugin
version: 1.0 version: 1.0
author: author author: author
main: your.main.path.Here main: com.example.plugin.ExamplePlugin
depend: ["PlaceholderAPI"] # (1) depend: ["PlaceholderAPI"] # (1)
``` ```
@@ -111,7 +174,7 @@ Tab the :material-plus-circle: icons in the code block below for additional info
name: ExamplePlugin name: ExamplePlugin
version: 1.0 version: 1.0
author: author author: author
main: your.main.path.Here main: com.example.plugin.ExamplePlugin
dependencies: dependencies:
server: server:
@@ -134,7 +197,7 @@ Tab the :material-plus-circle: icons in the code block below for additional info
name: ExamplePlugin name: ExamplePlugin
version: 1.0 version: 1.0
author: author author: author
main: your.main.path.Here main: com.example.plugin.ExamplePlugin
dependencies: dependencies:
server: server:
@@ -149,6 +212,42 @@ dependencies:
/// ///
/// tab | manifest.json (Hytale)
//// tab | Optional dependency
```{ .json .annotate title="manifest.json" }
{
"Group": "com.example",
"Name": "ExamplePlugin",
"Version": "1.0",
"Main": "com.example.plugin.ExamplePlugin",
"OptionalDependencies": {
"HelpChat:PlaceholderAPI": ">= 1.0.2"
}
}
```
////
//// tab | Required dependency
```{ .json .annotate title="manifest.json" }
{
"Group": "com.example",
"Name": "ExamplePlugin",
"Version": "1.0",
"Main": "com.example.plugin.ExamplePlugin",
"Dependencies": {
"HelpChat:PlaceholderAPI": ">= 1.0.2"
}
}
```
////
///
## Adding placeholders to PlaceholderAPI ## Adding placeholders to PlaceholderAPI
A full guide on how to create expansions can be found on the [Creating a PlaceholderExpansion](creating-a-placeholderexpansion.md) page. A full guide on how to create expansions can be found on the [Creating a PlaceholderExpansion](creating-a-placeholderexpansion.md) page.
@@ -156,15 +255,23 @@ A full guide on how to create expansions can be found on the [Creating a Placeho
## Setting placeholders in your plugin ## Setting placeholders in your plugin
PlaceholderAPI offers the ability, to automatically parse placeholders from other plugins within your own plugin, giving the ability for your plugin to support thousands of other placeholders without depending on each plugin individually. PlaceholderAPI offers the ability, to automatically parse placeholders from other plugins within your own plugin, giving the ability for your plugin to support thousands of other placeholders without depending on each plugin individually.
To use placeholders from other plugins in our own plugin, we simply have to [(soft)depend on PlaceholderAPI](#set-placeholderapi-as-softdepend) and use the `setPlaceholders` method. To use placeholders from other plugins in your own plugin, you simply have to [(soft)depend on PlaceholderAPI](#set-placeholderapi-as-softdepend) and use the `setPlaceholders` method.
It is also important to point out, that any required plugin/dependency for an expansion has to be on the server and enabled, or the `setPlaceholders` method will just return the placeholder itself (do nothing). It is also important to point out, that any required plugin/dependency for an expansion has to be on the server and enabled, or the `setPlaceholders` method will just return the placeholder itself (do nothing).
/// details | Example /// info | New since 2.12.0
type: example Starting with version 2.12.0 is it now possible to provide Components from the Adventure library to have placeholders parsed in.
Let's assume we want to send a custom join message that shows the primary group a player has. In order to use this new feature are the following things required to be true:
To achieve this, we can do the following:
- You depend on `placeholderapi-paper` and not just `placeholderapi`
- Your plugin runs on a Paper-based Server. Spigot-based servers will not work!
- You use `PAPIComponent` instead of `PlaceholderAPI` to parse Components.
///
/// tab | Spigot, Paper, ...
The following is an example plugin that sends `%player_name% joined the server! They are rank %vault_rank%` as the Join message, having the placeholders be replaced by PlaceholderAPI.
//// note | //// note |
The below example assumes a **soft dependency** on PlaceholderAPI to handle PlaceholderAPI not being present more decently. The below example assumes a **soft dependency** on PlaceholderAPI to handle PlaceholderAPI not being present more decently.
@@ -173,7 +280,7 @@ Tab the :material-plus-circle: icons in the code block below for additional info
//// ////
```{ .java .annotate title="JoinExample.java" } ```{ .java .annotate title="JoinExample.java" }
package at.helpch.placeholderapi; package com.example.plugin;
import me.clip.placeholderapi.PlaceholderAPI; import me.clip.placeholderapi.PlaceholderAPI;
@@ -215,4 +322,50 @@ public class JoinExample extends JavaPlugin implements Listener {
In our example are we providing a text containing `%player_name%` and `%vault_rank%` to be parsed, which require the Player and Vault expansion respectively. In our example are we providing a text containing `%player_name%` and `%vault_rank%` to be parsed, which require the Player and Vault expansion respectively.
Example output: `Notch joined the server! They are rank Admin` Example output: `Notch joined the server! They are rank Admin`
//// info | New since 2.12.0
Using `placeholderapi-papi` and `PAPIComponents` instead of `PlaceholderAPI` allows you to parse placeholders inside Adventure Components.
////
///
/// tab | Hytale
The following is an example plugin that sends `Welcome %player_name%!` as the Join message, having the placeholders be replaced by PlaceholderAPI.
``` { .java .annotate title="JoinExample.java" }
packate com.example.plugin;
import at.helpch.placeholderapi.PlaceholderAPI;
import com.hypixel.hytale.server.core.event.events.player.PlayerReadyEvent;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.plugin.JavaPlugin;
import com.hypixel.hytale.server.core.plugin.JavaPluginInit;
import com.hypixel.hytale.server.core.universe.Universe;
public class JoinExample extends JavaPlugin {
public JoinExample(JavaPluginInit init) {
super(init)
}
@Override
protected void setup() {
// (1)
Universe.get().getWorlds().keySet().forEach(name -> getEventRegistry().register(PlayerReadyEvent.class, name, this::onPlayerReady));
}
public void onPlayerReady(PlayerReadyEvent event) {
Player player = event.getPlayer();
// (2)
player.sendMessage(PlaceholderAPI.setPlaceholders(Message.raw("Welcome %player_name%!"), player))
}
}
```
1. We tell the server to call `onPlayerReady` whenever a `PlayerReadyEvent` fires.
2. PlaceholderAPI offers multiple `setPlaceholders` methods that can either return a `String` or a `Message` object, depending on your needs.
Note that these methods require input of the same type: `setPlaceholders(String, PlayerRef)` for String and `setPlaceholders(Message, PlayerRef)` for Messages.
/// ///