Skip to content

Commit

Permalink
feat: Add placeholder parse support
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelillo15 committed Sep 16, 2024
1 parent 8117e5b commit d304dc5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions NookureStaff-API/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies {
compileOnlyApi(rootProject.libs.miniMessage)
compileOnlyApi(rootProject.libs.caffeine)
compileOnlyApi(rootProject.libs.ebean)
compileOnlyApi(rootProject.libs.placeholderApi)
annotationProcessor(rootProject.libs.ebean)

compileOnly(libs.auto.service.annotations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

import static com.nookure.staff.api.util.ServerUtils.hasClass;

public abstract class TextUtils {
private static final boolean IS_PAPI_INSTALLED = hasClass("me.clip.placeholderapi.PlaceholderAPI");
private static final long SECOND = 1000;
private static final long MINUTE = 60 * SECOND;
private static final long HOUR = 60 * MINUTE;
Expand Down Expand Up @@ -117,4 +121,10 @@ public static String formatTime(long time) {
}
return buf.toString();
}

public static String parsePlaceholdersWithPAPI(@NotNull final org.bukkit.entity.Player player, @NotNull final String message) {
if (!IS_PAPI_INSTALLED) return message;

return me.clip.placeholderapi.PlaceholderAPI.setPlaceholders(player, message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.nookure.staff.api.util.DefaultFontInfo;
import com.nookure.staff.api.util.Scheduler;
import com.nookure.staff.api.util.ServerUtils;
import com.nookure.staff.api.util.TextUtils;
import io.ebean.Database;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
Expand Down Expand Up @@ -172,6 +173,7 @@ public void sendMiniMessage(@NotNull String message, String... placeholders) {

message = message.replace("{prefix}", nookPlugin.getPrefix());
message = DefaultFontInfo.centerIfContains(message);
message = TextUtils.parsePlaceholdersWithPAPI(player, message);

sendMessage(MiniMessage.miniMessage().deserialize(message));
}
Expand Down

0 comments on commit d304dc5

Please sign in to comment.