-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hooks): add placeholder api boilerplate
- Loading branch information
1 parent
4a9a938
commit d78b9b7
Showing
4 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
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
50 changes: 50 additions & 0 deletions
50
src/main/java/io/github/exampleuser/exampleplugin/hooks/PAPIExpansion.java
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,50 @@ | ||
package io.github.exampleuser.exampleplugin.hooks; | ||
|
||
import io.github.exampleuser.exampleplugin.ExamplePlugin; | ||
import me.clip.placeholderapi.expansion.PlaceholderExpansion; | ||
import org.bukkit.OfflinePlayer; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* A PlaceholderAPI expansion. Read the docs at <a href="https://wiki.placeholderapi.com/developers/creating-a-placeholderexpansion/">here</a> on how to register your custom placeholders. | ||
*/ | ||
public class PAPIExpansion extends PlaceholderExpansion { | ||
private final ExamplePlugin plugin; | ||
|
||
public PAPIExpansion(ExamplePlugin plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("UnstableApiUsage") | ||
public @NotNull String getIdentifier() { | ||
return plugin.getPluginMeta().getName().replace(' ', '_').toLowerCase(); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("UnstableApiUsage") | ||
public @NotNull String getAuthor() { | ||
return String.join(", ", plugin.getPluginMeta().getAuthors()); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("UnstableApiUsage") | ||
public @NotNull String getVersion() { | ||
return plugin.getPluginMeta().getVersion(); | ||
} | ||
|
||
@Override | ||
public boolean persist() { | ||
return true; // This needs to be true, or PlaceholderAPI will unregister the expansion during a plugin reload. | ||
} | ||
|
||
@Override | ||
public @Nullable String onRequest(OfflinePlayer p, @NotNull String params) { | ||
return switch (params) { | ||
case "example" -> "placeholder text"; | ||
case "example2" -> "placeholder text2"; | ||
default -> null; | ||
}; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/io/github/exampleuser/exampleplugin/hooks/PAPIHook.java
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 @@ | ||
package io.github.exampleuser.exampleplugin.hooks; | ||
|
||
import io.github.exampleuser.exampleplugin.ExamplePlugin; | ||
import io.github.exampleuser.exampleplugin.Reloadable; | ||
import org.bukkit.Bukkit; | ||
|
||
/** | ||
* A hook to interface with <a href="https://wiki.placeholderapi.com/">PlaceholderAPI</a>. | ||
*/ | ||
public class PAPIHook implements Reloadable { | ||
private final ExamplePlugin plugin; | ||
private final static String pluginName = "PlaceholderAPI"; | ||
private PAPIExpansion PAPIExpansion; | ||
|
||
/** | ||
* Instantiates a new PlaceholderAPI hook. | ||
* | ||
* @param plugin the plugin instance | ||
*/ | ||
public PAPIHook(ExamplePlugin plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
@Override | ||
public void onLoad() { | ||
} | ||
|
||
@Override | ||
public void onEnable() { | ||
if (!Bukkit.getPluginManager().isPluginEnabled(pluginName)) | ||
return; | ||
|
||
PAPIExpansion = new PAPIExpansion(plugin); | ||
} | ||
|
||
@Override | ||
public void onDisable() { | ||
PAPIExpansion.unregister(); | ||
PAPIExpansion = null; | ||
} | ||
} |