Skip to content

Commit

Permalink
feat: Added support for returning strings instead of
Browse files Browse the repository at this point in the history
converting placeholder to component
  • Loading branch information
4drian3d committed May 7, 2023
1 parent 22a65cb commit 94f2c1c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ Its operation would be similar to running the `/papi parse me (placeholders)` co

This placeholder requires two online players to work.
The functioning of this placeholder depends on whether the plugin in which it is used has relational placeholder support

If you want to nest the result of the placeholder inside another placeholder, add the string argument.
For example: `<placeholderapi_player:%player_name%:string>`

## Downloads

[![](https://raw.githubusercontent.com/Prospector/badges/master/modrinth-badge-72h-padded.png)](https://modrinth.com/plugin/miniplaceholders-placeholderapi-expansion)
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group = io.github.miniplaceholders
version = 1.0.0
version = 1.1.0
description = PlaceholderAPI-Expansion
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import io.github.miniplaceholders.api.utils.LegacyUtils;
import me.clip.placeholderapi.PlaceholderAPI;
import net.kyori.adventure.text.minimessage.tag.resolver.ArgumentQueue;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

import io.github.miniplaceholders.api.Expansion;
import net.kyori.adventure.text.minimessage.tag.Tag;

import static net.kyori.adventure.text.minimessage.MiniMessage.miniMessage;
import static net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.*;

@SuppressWarnings("unused")
public final class PaperPlugin extends JavaPlugin {

@Override
Expand All @@ -25,7 +28,11 @@ public void onEnable(){
argument
).replace(SECTION_CHAR, AMPERSAND_CHAR);

return Tag.selfClosingInserting(LegacyUtils.parsePossibleLegacy(papiParsed));
if (parseString(queue)) {
return Tag.preProcessParsed(miniMessage().serialize(LegacyUtils.parsePossibleLegacy(papiParsed)));
} else {
return Tag.selfClosingInserting(LegacyUtils.parsePossibleLegacy(papiParsed));
}
})
.audiencePlaceholder("player", (aud, queue, ctx) -> {
final String argument = queue.popOr("You need to provide a placeholder").value();
Expand All @@ -34,7 +41,11 @@ public void onEnable(){
argument
).replace(SECTION_CHAR, AMPERSAND_CHAR);

return Tag.selfClosingInserting(LegacyUtils.parsePossibleLegacy(papiParsed));
if (parseString(queue)) {
return Tag.preProcessParsed(miniMessage().serialize(LegacyUtils.parsePossibleLegacy(papiParsed)));
} else {
return Tag.selfClosingInserting(LegacyUtils.parsePossibleLegacy(papiParsed));
}
})
.relationalPlaceholder("relational", (player, toShow, queue, ctx) -> {
final String argument = queue.popOr("You need to provide a placeholder").value();
Expand All @@ -44,9 +55,17 @@ public void onEnable(){
argument
).replace(SECTION_CHAR, AMPERSAND_CHAR);

return Tag.selfClosingInserting(LegacyUtils.parsePossibleLegacy(papiParsed));
if (parseString(queue)) {
return Tag.preProcessParsed(miniMessage().serialize(LegacyUtils.parsePossibleLegacy(papiParsed)));
} else {
return Tag.selfClosingInserting(LegacyUtils.parsePossibleLegacy(papiParsed));
}
})
.build()
.register();
}

private boolean parseString(ArgumentQueue queue) {
return queue.hasNext() && queue.pop().lowerValue().equals("string");
}
}

0 comments on commit 94f2c1c

Please sign in to comment.