Merge pull request #1158 from PlaceholderAPI/feature/wiki-add-component-info

[Wiki] Add info on new Component support
This commit is contained in:
Funnycube
2026-02-02 19:19:10 +11:00
committed by GitHub
3 changed files with 61 additions and 19 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

@@ -273,6 +273,9 @@ package com.example.plugin;
import com.example.plugin.expansion.SomeExpansion; import com.example.plugin.expansion.SomeExpansion;
import com.hypixel.hytale.server.core.plugin.JavaPlugin; import com.hypixel.hytale.server.core.plugin.JavaPlugin;
import com.hypixel.hytale.server.core.plugin.JavaPluginInit; 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 class SomePlugin extends JavaPlugin {
@@ -280,7 +283,12 @@ public class SomePlugin extends JavaPlugin {
super(init) super(init)
} }
// TODO: Example of checking for PAPI and registering expansion @Override
protected void start() {
if (HytaleServer.get().getPluginManager().getPlugin(PluginIdentifier.fromString("HelpChat:PlaceholderAPI")) != null) {
new SomeExpansion(this).register();
}
}
} }
``` ```

View File

@@ -6,10 +6,12 @@ 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
### Add PlaceholderAPI to your Project
Before you can actually make use of PlaceholderAPI, you first have to import it into your project. 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. Use the below code example matching your project type and dependency manager.
@@ -26,9 +28,16 @@ Use the below code example matching your project type and dependency manager.
<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>
``` ```
//// ////
@@ -42,7 +51,10 @@ 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}'
} }
``` ```
//// ////
@@ -72,7 +84,7 @@ dependencies {
<dependency> <dependency>
<groupId>at.helpch</groupId> <groupId>at.helpch</groupId>
<artifactId>placeholderapi-hytale</artifactId> <artifactId>placeholderapi-hytale</artifactId>
<version>{version}</version> <version>{papiHytaleVersion}</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>
@@ -91,16 +103,16 @@ repositories {
dependencies { dependencies {
// Replace {hytaleVersion} with the version you need. // Replace {hytaleVersion} with the version you need.
compileOnly 'com.hypixel.hytale:Server:{hytaleVersion}' compileOnly 'com.hypixel.hytale:Server:{hytaleVersion}'
compileOnly 'at.helpch:placeholderapi-hytale:{version}' compileOnly 'at.helpch:placeholderapi-hytale:{papiHytaleVersion}'
} }
``` ```
//// ////
/// ///
/// details | What is `{version}`? /// 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.
@@ -243,10 +255,20 @@ 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).
/// info | New since 2.12.0
Starting with version 2.12.0 is it now possible to provide Components from the Adventure library to have placeholders parsed in.
In order to use this new feature are the following things required to be true:
- 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, ... /// 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. 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.
@@ -301,11 +323,14 @@ public class JoinExample extends JavaPlugin implements Listener {
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 /// tab | Hytale
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. 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" } ``` { .java .annotate title="JoinExample.java" }
packate com.example.plugin; packate com.example.plugin;
@@ -316,6 +341,7 @@ import com.hypixel.hytale.server.core.event.events.player.PlayerReadyEvent;
import com.hypixel.hytale.server.core.Message; import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.plugin.JavaPlugin; import com.hypixel.hytale.server.core.plugin.JavaPlugin;
import com.hypixel.hytale.server.core.plugin.JavaPluginInit; import com.hypixel.hytale.server.core.plugin.JavaPluginInit;
import com.hypixel.hytale.server.core.universe.Universe;
public class JoinExample extends JavaPlugin { public class JoinExample extends JavaPlugin {
@@ -326,13 +352,14 @@ public class JoinExample extends JavaPlugin {
@Override @Override
protected void setup() { protected void setup() {
// (1) // (1)
getEventRegistry().registerGlobal(PlayerReadyEvent.class, this::onPlayerReady); Universe.get().getWorlds().keySet().forEach(name -> getEventRegistry().register(PlayerReadyEvent.class, name, this::onPlayerReady));
} }
public void onPlayerReady(PlayerReadyEvent event) { public void onPlayerReady(PlayerReadyEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
// (2) // (2)
player.sendMessage(PlaceholderAPI.setPlaceholders(Message.raw("Welcome %player_name%!"), player)) player.sendMessage(PlaceholderAPI.setPlaceholders(Message.raw("Welcome %player_name%!"), player))
} }
} }
``` ```