mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2025-10-27 17:21:58 +01:00
Move to MkDocs Wiki setup
This commit is contained in:
480
docs/developers/creating-a-placeholderexpansion.md
Normal file
480
docs/developers/creating-a-placeholderexpansion.md
Normal file
@@ -0,0 +1,480 @@
|
||||
# Creating a PlaceholderExpansion
|
||||
|
||||
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.
|
||||
You can download expansions either directly from the eCloud yourself, or download them through the [download command of PlaceholderAPI](../commands.md#papi-ecloud-download).
|
||||
|
||||
## Table of contents
|
||||
|
||||
- [Getting started](#getting-started)
|
||||
- [Common Expansion Parts](#common-expansion-parts)
|
||||
- [Making an Internal Expansion](#making-an-internal-expansion)
|
||||
- [Full Example](#full-example-internal)
|
||||
- [Register your Expansion](#register-your-expansion)
|
||||
- [Making an External Expansion](#making-an-external-expansion)
|
||||
- [Full Example (Without Dependency)](#full-example-external-no-dependency)
|
||||
- [Full Example (With Dependency)](#full-example-external-dependency)
|
||||
- [Making a relational Expansion](#making-a-relational-expansion)
|
||||
- [Full Example](#full-example-relational)
|
||||
|
||||
## Getting started
|
||||
|
||||
For starters, you need to decide what type of [`PlaceholderExpansion`][placeholderexpansion] you want to create. There are various ways to create an expansion. This page will cover the most common ones.
|
||||
|
||||
### Common Expansion Parts
|
||||
|
||||
All shown examples will share the same common parts that belong the the [`PlaceholderExpansion`][placeholderexpansion] class.
|
||||
In order to not repeat the same basic info for each method throughout this page, and to greatly reduce the overall length, we will cover the most basic/necessary ones here.
|
||||
|
||||
#### Basic PlaceholderExpansion Structure
|
||||
|
||||
/// note |
|
||||
Tab the :material-plus-circle: icons in the code block below for additional information.
|
||||
///
|
||||
|
||||
```{ .java .annotate title="SomeExpansion.java" }
|
||||
package at.helpch.placeholderapi.example.expansion;
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
|
||||
public class SomeExpansion extends PlaceholderExpansion {
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return "Author"; // (1)
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return "example"; // (2)
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return "1.0.0"; // (3)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
1. This method allows you to set the name of the expansion's author.
|
||||
|
||||
2. The identifier is the part in the placeholder that is between the first `%` (or `{` if bracket placeholders are used) and the first `_`.
|
||||
The identifier may not contain `%`, `{`, `}` or `_`.
|
||||
|
||||
If you still want to use them in your expansion name, override the `getName()` method.
|
||||
|
||||
3. This method returns the version of the expansion.
|
||||
Due to it being a string are you not limited to numbers alone, but it is recommended to stick with a number pattern.
|
||||
|
||||
PlaceholderAPI uses this String to compare with the latest version on the eCloud (if uploaded to it) to see if a new version is available.
|
||||
If your expansion is included in a plugin, this does not matter.
|
||||
|
||||
You must also choose between one of these two methods for handling the actual parsing of placeholders (Exception being expansions providing [relational placeholders](#making-a-relational-expansion)):
|
||||
|
||||
- `onRequest(OfflinePlayer, String)`
|
||||
The first parameter is the player that the placeholders are parsed against, given as an OfflinePlayer instance. This can be null.
|
||||
The second parameter is the content of the placeholder after the first `_` and before the closing `%` (or `}` if bracket placeholders are used). This String is never null.
|
||||
|
||||
If not explicity overriden, this will automatically call `onPlaceholderRequest(Player, String)`, passing the parameters as-is to it.
|
||||
This method is recommended as it allows the usage of offline players, meaning the player does not need to be online to obtain certain certain data from them such as name or UUID.
|
||||
|
||||
- `onPlaceholderRequest(Player, String)`
|
||||
The first parameter is the player that the placeholders are parsed against, given as a Player instance. This can be null.
|
||||
The second parameter is the content of the placeholder after the first `_` and before the closing `%` (or `}` if bracket placeholders are used). This String is never null.
|
||||
|
||||
If not set, this method will return `null` which PlaceholderAPI sees as an invalid placeholder.
|
||||
|
||||
/// note
|
||||
PlaceholderAPI always calls `onRequest(Player, String)` in a PlaceholderExpansion.
|
||||
///
|
||||
|
||||
----
|
||||
|
||||
## Making an Internal Expansion
|
||||
|
||||
Internal PlaceholderExpansions are classes directly integrated in the plugin they depend on.
|
||||
This method of creating a PlaceholderExpansion is recommended as it has the following benefits:
|
||||
|
||||
- No `canRegister()` method override required. Since your expansion is part of the plugin it depends on is this override not required.
|
||||
- Easier access to plugin data. Using dependency injection, you can more easily access data of your plugin such as config values.
|
||||
|
||||
/// warning | Important!
|
||||
Internal PlaceholderExpansions are not automatically registered by PlaceholderAPI, due to them not being a separate jar file located in the expansion folder.
|
||||
Please see the [Regsister your Expansion](#register-your-expansion) section for more details.
|
||||
|
||||
You are also required to override and set `persistent()` to `true`. This tells PlaceholderAPI to not unload your expansion during plugin reload, as it would otherwise unregister your expansion, making it no longer work.
|
||||
///
|
||||
|
||||
/// details | Full Example
|
||||
attrs: { id: full-example-internal }
|
||||
type: example
|
||||
|
||||
//// note |
|
||||
Please see the [Basic PlaceholderExpansion Structure](#basic-placeholderexpansion-structure) section for an explanation of all common methods in this example.
|
||||
|
||||
Tab the :material-plus-circle: icons in the code block below for additional information.
|
||||
////
|
||||
|
||||
```{ .java .annotate title="SomeExpansion.java" }
|
||||
package at.helpch.placeholderapi.example.expansion;
|
||||
|
||||
import at.helpch.placeholderapi.example.SomePlugin;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SomeExpansion extends PlaceholderExpansion {
|
||||
|
||||
private final SomePlugin plugin; // (1)
|
||||
|
||||
public SomeExpansion(SomePlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getAuthor() {
|
||||
return String.join(", ", plugin.getDescription().getAuthors()); // (2)
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getIdentifier() {
|
||||
return "example";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getVersion() {
|
||||
return plugin.getDescription().getVersion(); // (3)
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean persist() {
|
||||
return true; // (4)
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onRequest(OfflinePlayer player, @NotNull String params) {
|
||||
if (params.equalsIgnoreCase("placeholder1")) {
|
||||
return plugin.getConfig().getString("placeholders.placeholder1", "default1"); // (5)
|
||||
}
|
||||
|
||||
if (params.equalsIgnoreCase("placeholder2")) {
|
||||
return plugin.getConfig().getString("placeholders.placeholder1", "default1"); // (6)
|
||||
}
|
||||
|
||||
return null; // (7)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
1. Mockup plugin used to showcase the use of dependency injection to access specific plugin related data.
|
||||
|
||||
2. We can use the authors set in the plugin's `plugin.yml` file as the authors of this expansion.
|
||||
|
||||
3. Since our expansion is internal can this version be the same as the one defined in the plugin's `plugin.yml` file.
|
||||
|
||||
4. This needs to be set, or else will PlaceholderAPI unregister our expansion during a plugin reload.
|
||||
|
||||
5. 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.
|
||||
///
|
||||
|
||||
### Register your Expansion
|
||||
|
||||
Due to the PlaceholderExpansion being internal, does PlaceholderAPI not load it automatically, requiring us to do it manually.
|
||||
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:
|
||||
|
||||
```{ .java .annotate title="SomePlugin.java" }
|
||||
package at.helpch.placeholderapi.example;
|
||||
|
||||
import at.helpch.placeholderapi.example.expansion.SomeExpansion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class SomePlugin extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) { // (1)
|
||||
new SomeExpansion(this).register(); // (2)
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
1. We check that PlaceholderAPI is present and enabled on the server, or else we would get Exceptions.
|
||||
Also, make sure you [set PlaceholderAPI as depend or softdepend](using-placeholderapi.md#set-placeholderapi-as-softdepend) in your plugin's `plugin.yml` file!
|
||||
|
||||
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.
|
||||
|
||||
----
|
||||
|
||||
## Making an External Expansion
|
||||
|
||||
External Expansions are separate Jar files located inside PlaceholderAPI's `expansions` folder, that contain the [`PlaceholderExpansion`][placeholderexpansion] extending class.
|
||||
It is recommended to only make external Expansions for the following situations.
|
||||
|
||||
- Your expansion does not rely on a plugin.
|
||||
- Your expansion depends on a plugin and you can't directly include it (Plugin is not your own).
|
||||
|
||||
Should the above cases not match your situation, meaning your expansion is for a plugin you maintain, is the creation of an [internal Expansion](#making-an-internal-expansion) recommended.
|
||||
|
||||
Some benefits of an external expansion include automatic (re)loading of your expansion by PlaceholderAPI and having the option to [upload it to the eCloud](expansion-cloud.md) allowing the download of it through the [`/papi ecloud download` command](../commands.md#papi-ecloud-download).
|
||||
Downsides include a more tedious setup in terms of checking for a required plugin being present.
|
||||
|
||||
/// details | Full Example (Without Dependency)
|
||||
attrs: { id: full-example-external-no-dependency }
|
||||
type: example
|
||||
|
||||
//// note |
|
||||
Please see the [Basic PlaceholderExpansion Structure](#basic-placeholderexpansion-structure) section for an explanation of all common methods in this example.
|
||||
|
||||
Tab the :material-plus-circle: icons in the code block below for additional information.
|
||||
////
|
||||
|
||||
This is an example expansion without any plugin dependency.
|
||||
|
||||
```{ .java .annotate title="SomeExpansion.java" }
|
||||
package at.helpch.placeholderapi.example.expansion;
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SomeExpansion extends PlaceholderExpansion {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getAuthor() {
|
||||
return "Author";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getIdentifier() {
|
||||
return "example";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getVersion() {
|
||||
return "1.0.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onRequest(OfflinePlayer player, @NotNull String params) {
|
||||
if (params.equalsIgnoreCase("placeholder1")) {
|
||||
return "text1";
|
||||
}
|
||||
|
||||
if (params.equalsIgnoreCase("placeholder2")) {
|
||||
return "text2";
|
||||
}
|
||||
|
||||
return null; // (1)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
1. Reaching this means that an invalid params String was given, so we return `null` to tell PlaceholderAPI that the placeholder was invalid.
|
||||
///
|
||||
|
||||
/// details | Full Example (With Dependency)
|
||||
attrs: { id: full-example-external-dependency }
|
||||
type: example
|
||||
|
||||
//// note |
|
||||
Please see the [Basic PlaceholderExpansion Structure](#basic-placeholderexpansion-structure) section for an explanation of all common methods in this example.
|
||||
|
||||
Tab the :material-plus-circle: icons in the code block below for additional information.
|
||||
////
|
||||
|
||||
This is an example expansion with a plugin dependency.
|
||||
|
||||
```{ .java .annotate title="SomeExpansion.java" }
|
||||
package at.helpch.placeholderapi.example.expansion;
|
||||
|
||||
import at.helpch.placeholderapi.example.SomePlugin;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SomeExpansion extends PlaceholderExpansion {
|
||||
|
||||
private SomePlugin plugin; // (1)
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getAuthor() {
|
||||
return "Author";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getIdentifier() {
|
||||
return "example";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getVersion() {
|
||||
return "1.0.0"
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRequiredPlugin() {
|
||||
return "SomePlugin"; // (2)
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRegister() { // (3)
|
||||
return (plugin = (SomePlugin) Bukkit.getPluginManager().getPlugin(getRequiredPlugin())) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onRequest(OfflinePlayer player, @NotNull String params) {
|
||||
if (params.equalsIgnoreCase("placeholder1")) {
|
||||
return plugin.getConfig().getString("placeholders.placeholder1", "default1"); // (4)
|
||||
}
|
||||
|
||||
if (params.equalsIgnoreCase("placeholder2")) {
|
||||
return plugin.getConfig().getString("placeholders.placeholder1", "default1"); // (5)
|
||||
}
|
||||
|
||||
return null; // (6)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
1. We set the value of this instance in the `canRegister()` method, which means that it can't be set to be final.
|
||||
|
||||
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.
|
||||
|
||||
3. 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`.
|
||||
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.
|
||||
|
||||
4. Example of accessing data of the plugin's `config.yml` file.
|
||||
|
||||
5. Example of accessing data of the plugin's `config.yml` file.
|
||||
|
||||
6. Reaching this means that an invalid params String was given, so we return `null` to tell PlaceholderAPI that the placeholder was invalid.
|
||||
///
|
||||
|
||||
----
|
||||
|
||||
## Making a relational Expansion
|
||||
|
||||
/// note
|
||||
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 PlaceholderExpansions are special in that bthey take two players as input, allowing you to give outputs based on their relation to each other.
|
||||
|
||||
To create a relational expansion you will need to implement the [`Relational`][relational] interface into your expansion. You also still need to extend the [`PlaceholderExpansion`][placeholderexpansion] class.
|
||||
Implementing this interface will add the `onPlaceholderRequest(Player, Player, String)` with the first two arguments being the first and second player to use and the third argument being the content after the second `_` and before the final `%` (Or `}` if bracket placeholders are used) in the placeholder.
|
||||
|
||||
/// details | Full Example
|
||||
attrs: { id: full-example-relational }
|
||||
type: example
|
||||
|
||||
//// note |
|
||||
Please see the [Basic PlaceholderExpansion Structure](#basic-placeholderexpansion-structure) section for an explanation of all common methods in this example.
|
||||
|
||||
Tab the :material-plus-circle: icons in the code block below for additional information.
|
||||
////
|
||||
|
||||
This is a complete example of using relational placeholders.
|
||||
For the sake of simplicity are we using the [internal Expansion setup](#making-an-internal-expansion) here and assume that `SomePlugin` offers a `areFriends(Player, Player)` method that returns true or false based on if the players are friends or not.
|
||||
|
||||
```{ .java .annotate title="SomeExpansion.java" }
|
||||
package at.helpch.placeholderapi.example.expansion;
|
||||
|
||||
import at.helpch.placeholderapi.example.SomePlugin;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import me.clip.placeholderapi.expansion.Relational
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SomeExpansion extends PlaceholderExpansion implements Relational {
|
||||
|
||||
private final SomePlugin plugin; // (1)
|
||||
|
||||
public SomeExpansion(SomePlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getAuthor() {
|
||||
return String.join(", ", plugin.getDescription().getAuthors()); // (2)
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getIdentifier() {
|
||||
return "example";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getVersion() {
|
||||
return plugin.getDescription().getVersion(); // (3)
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean persist() {
|
||||
return true; // (4)
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onPlaceholderRequest(Player one, Player two, String identifier) {
|
||||
if (one == null || two == null) {
|
||||
return null; // (5)
|
||||
}
|
||||
|
||||
if (identifier.equalsIgnoreCase("friends")) { // (6)
|
||||
if (plugin.areFriends(one, two)) {
|
||||
return ChatColor.GREEN + one.getName() + " and " + two.getName() + " are friends!";
|
||||
} else {
|
||||
return ChatColor.RED + one.getName() + " and " + two.getName() + " are not friends!";
|
||||
}
|
||||
}
|
||||
|
||||
return null; // (7)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
1. Mockup plugin used to showcase the use of dependency injection to access specific plugin related data.
|
||||
|
||||
2. We can use the authors set in the plugin's `plugin.yml` file as the authors of this expansion.
|
||||
|
||||
3. Since our expansion is internal can this version be the same as the one defined in the plugin's `plugin.yml` file.
|
||||
|
||||
4. This needs to be set, or else will PlaceholderAPI unregister our expansion during a plugin reload.
|
||||
|
||||
5. Our placeholder requires both players to be present, so if either one is not will this return null.
|
||||
|
||||
6. In case the identifier matches (Meaning the placeholder is `%rel_example_friends%` or `{rel_example_friends}`) will we check if Player one and two are friends through our plugin's `areFriends(Player, Player)` method.
|
||||
Should they be friends, return green text saying they are and else return red text saying they aren't.
|
||||
|
||||
7. Reaching this means that an invalid params String was given, so we return `null` to tell PlaceholderAPI that the placeholder was invalid.
|
||||
|
||||
Don't forget to [register your expansion](#register-your-expansion).
|
||||
///
|
||||
|
||||
[placeholderexpansion]: https://github.com/PlaceholderAPI/PlaceholderAPI/blob/master/src/main/java/me/clip/placeholderapi/expansion/PlaceholderExpansion.java
|
||||
[relational]: https://github.com/PlaceholderAPI/PlaceholderAPI/blob/master/src/main/java/me/clip/placeholderapi/expansion/Relational.java
|
||||
82
docs/developers/expansion-cloud.md
Normal file
82
docs/developers/expansion-cloud.md
Normal file
@@ -0,0 +1,82 @@
|
||||
# eCloud
|
||||
|
||||
## About
|
||||
|
||||
PlaceholderAPI uses an expansion-cloud (A website that has all kinds of expansions stored), to download jar files, that contain the placeholders for it to use.
|
||||
|
||||
The expansion-cloud can be seen under https://api.extendedclip.com/home
|
||||
|
||||
## How it works
|
||||
|
||||
PlaceholderAPI connects to the ecloud on startup of your server, to check if the cloud is available and how many expansions are available on it.
|
||||
If you run [`/papi ecloud download <expansion>`](../commands.md#papi-ecloud-download), PlaceholderAPI will connect to the site to first check if the specified expansion exists and then downloads it if it does.
|
||||
|
||||
/// note
|
||||
PlaceholderAPI can only download expansions that are verified on the eCloud. Any unverified expansion needs to be downloaded manually.
|
||||
///
|
||||
|
||||
You can disable the connection to the cloud by setting `cloud_enabled` in the config.yml to false.
|
||||
|
||||
## Adding your own expansion
|
||||
|
||||
You can add your own expansion to the expansion-cloud for others to use.
|
||||
In order to do that, you have to follow those steps:
|
||||
|
||||
1. Make sure you have created a seperate jar file as described in the [Creating a PlaceholderExpansion](creating-a-placeholderexpansion.md) page.
|
||||
2. Create an account on the site, or log in, if you already have one.
|
||||
3. Click on `Expansions` and then on [`Upload New`](https://api.extendedclip.com/manage/add/).
|
||||
4. Fill out the required information. `Source URL` and `Dependency URL` are optional and would link to the source code and any dependency (plugin) of your expansion respectively.
|
||||
5. Click on the button that says `Choose an file...` and select the jar of your expansion.
|
||||
- **Important!** Make sure, that the name of the jar file contains the same version like you set in the version field.
|
||||
6. Click on `Submit Expansion`
|
||||
|
||||
Your expansion is now uploaded and will be reviewed by a moderator.
|
||||
If everything is ok will your expansion be approved and will be available on the ecloud for PlaceholderAPI*.
|
||||
|
||||
/// info | Note for Hosts
|
||||
You can block specific expansions from being downloaded using the `PAPI_BLOCKED_EXPANSIONS` environment variable.
|
||||
Just define it with a value of comma-separated expansion names that should not be downloadable by PlaceholderAPI.
|
||||
|
||||
This feature exists since version 2.11.4 of PlaceholderAPI.
|
||||
///
|
||||
|
||||
## Updating your expansion
|
||||
|
||||
Before you update, please note the following:
|
||||
Updating your expansion will automatically make it unverified, requiring a site moderator to verify it again. This was made to combat malware from being uploaded and distributed.
|
||||
|
||||
To update your expansion, you first have to go to the list of [your expansions](https://api.extendedclip.com/manage/).
|
||||
For that click on `Expansions` and select `Your Expansions`.
|
||||
After that, follow those steps:
|
||||
|
||||
1. Click the name of the expansion, that you want to update.
|
||||
2. Click on the button that says `Version`
|
||||
3. Click on `Add Version`
|
||||
4. Fill out the fields and upload the new jar.
|
||||
- **Important!** Make sure, that the name of the jar file contains the same version like you set in the version-field!
|
||||
5. Click on `Save Changes`
|
||||
|
||||
Your version should now be uploaded to the eCloud. You can now ask a responsible staff member on the [HelpChat Discord](https://discord.gg/helpchat) to review your expansion to get it re-verified. Please remain patient and polite when asking.
|
||||
|
||||
## Downloading a specific expansion version
|
||||
|
||||
In some cases, you may want to use a specific, older version of an expansion. Such a case could be for example, when you run an old server version and the newest version of an expansion uses methods that aren't available on that particular server version, causing compatability issues.
|
||||
For that case is there a way, to download a specific version of expansion. You can download the expansion either manually, or through PlaceholderAPI itself.
|
||||
Here is how you can do it for each.
|
||||
|
||||
### Download with PlaceholderAPI
|
||||
|
||||
This is the easiest of both methods since it requires the least amount of effort.
|
||||
Run the following command in-game or in your console to download a specific version:
|
||||
[`/papi ecloud download <expansion> [version]`](../commands.md#papi-ecloud-download)
|
||||
|
||||
To find out, what versions are available for the expansion, run [`/papi ecloud info <expansion>`](../commands.md#papi-ecloud-info).
|
||||
|
||||
After you downloaded the specific version, run [`/papi reload`](../commands.md#papi-reload) to refresh the installed expansions.
|
||||
|
||||
### Download manually
|
||||
|
||||
To download an expansion manually, you first have to connect to the website and go to the expansion of your choice.
|
||||
There, you click on the button that says `Version` and click on the download-icon of the version you want to download.
|
||||
|
||||
Finally, stop your server, upload the jar to the folder in `/plugins/PlaceholderAPI/expansions` (Make sure to delete the old jar, if there's already one) and start the server again.
|
||||
175
docs/developers/using-placeholderapi.md
Normal file
175
docs/developers/using-placeholderapi.md
Normal file
@@ -0,0 +1,175 @@
|
||||
# Using PlaceholderAPI
|
||||
|
||||
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**!
|
||||
|
||||
## First steps
|
||||
|
||||
Before you can actually make use of PlaceholderAPI, you first have to import it into your project.
|
||||
|
||||
/// tab | :simple-apachemaven: Maven
|
||||
```{ .xml title="pom.xml" data-md-component="api-version" }
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>placeholderapi</id>
|
||||
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>{version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
```
|
||||
///
|
||||
|
||||
/// tab | :simple-gradle: Gradle
|
||||
```{ .groovy title="build.gradle" data-md-component="api-version" }
|
||||
repositories {
|
||||
maven {
|
||||
url = 'https://repo.extendedclip.com/content/repositories/placeholderapi/'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly 'me.clip:placeholderapi:{version}'
|
||||
}
|
||||
```
|
||||
///
|
||||
|
||||
### Set PlaceholderAPI as (soft)depend
|
||||
|
||||
Next step is to go to your plugin.yml or paper-plugin.yml and add PlaceholderAPI as a depend or softdepend, depending (no pun intended) on if it is optional or not.
|
||||
|
||||
/// tab | :simple-spigotmc: plugin.yml
|
||||
|
||||
//// tab | Optional dependency
|
||||
```yaml
|
||||
name: ExamplePlugin
|
||||
version: 1.0
|
||||
author: author
|
||||
main: your.main.path.Here
|
||||
|
||||
# This sets PlaceholderAPI as an optional dependency for your plugin.
|
||||
softdepend: [PlaceholderAPI]
|
||||
```
|
||||
////
|
||||
|
||||
//// tab | Required dependency
|
||||
```yaml
|
||||
name: ExamplePlugin
|
||||
version: 1.0
|
||||
author: author
|
||||
main: your.main.path.Here
|
||||
|
||||
# This sets PlaceholderAPI as a required dependency for your plugin.
|
||||
depend: [PlaceholderAPI]
|
||||
```
|
||||
////
|
||||
|
||||
///
|
||||
|
||||
/// tab | :fontawesome-regular-paper-plane: paper-plugin.yml
|
||||
|
||||
//// tab | Optional dependency
|
||||
```yaml
|
||||
name: ExamplePlugin
|
||||
version: 1.0
|
||||
author: author
|
||||
main: your.main.path.Here
|
||||
|
||||
dependencies:
|
||||
server:
|
||||
PlaceholderAPI:
|
||||
# Load order is relative to the dependency. So here PlaceholderAPI loads before our plugin.
|
||||
load: BEFORE
|
||||
required: false
|
||||
```
|
||||
////
|
||||
|
||||
//// tab | Required dependency
|
||||
```yaml
|
||||
name: ExamplePlugin
|
||||
version: 1.0
|
||||
author: author
|
||||
main: your.main.path.Here
|
||||
|
||||
dependencies:
|
||||
server:
|
||||
PlaceholderAPI:
|
||||
# Load order is relative to the dependency. So here PlaceholderAPI loads before our plugin.
|
||||
load: BEFORE
|
||||
required: true
|
||||
```
|
||||
////
|
||||
|
||||
///
|
||||
|
||||
## 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.
|
||||
|
||||
## 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.
|
||||
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.
|
||||
|
||||
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).
|
||||
|
||||
**Example**:
|
||||
Let's assume we want to send a custom join message that shows the primary group a player has.
|
||||
To achieve this, we can do the following:
|
||||
```java
|
||||
package at.helpch.placeholderapi;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
|
||||
public class JoinExample extends JavaPlugin implements Listener {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
/*
|
||||
* We register the EventListener here, when PlaceholderAPI is installed.
|
||||
* Since all events are in the main class (this class), we simply use "this"
|
||||
*/
|
||||
Bukkit.getPluginManager().registerEvents(this, this);
|
||||
} else {
|
||||
/*
|
||||
* We inform about the fact that PlaceholderAPI isn't installed and then
|
||||
* disable this plugin to prevent issues.
|
||||
*/
|
||||
getLogger().warn("Could not find PlaceholderAPI! This plugin is required.");
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
String joinText = "%player_name% &ajoined the server! They are rank &f%vault_rank%";
|
||||
|
||||
/*
|
||||
* We parse the placeholders using "setPlaceholders"
|
||||
* This would turn %vault_rank% into the name of the Group, that the
|
||||
* joining player has, assuming Vault and the Vault expansion are
|
||||
* on the server.
|
||||
*/
|
||||
joinText = PlaceholderAPI.setPlaceholders(event.getPlayer(), joinText);
|
||||
|
||||
event.setJoinMessage(joinText);
|
||||
}
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user