mirror of
https://github.com/YouHaveTrouble/NotJustNameplates.git
synced 2026-05-11 22:16:57 +00:00
papi support
This commit is contained in:
@@ -15,10 +15,12 @@ java {
|
|||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven("https://repo.purpurmc.org/snapshots/")
|
maven("https://repo.purpurmc.org/snapshots/")
|
||||||
|
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
paperweight.paperDevBundle("1.20.1-R0.1-SNAPSHOT", "org.purpurmc.purpur")
|
paperweight.paperDevBundle("1.20.1-R0.1-SNAPSHOT", "org.purpurmc.purpur")
|
||||||
|
compileOnly("me.clip:placeholderapi:2.11.3")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
|
|||||||
@@ -20,10 +20,13 @@ public final class NotJustNameplates extends JavaPlugin {
|
|||||||
private final TeamManager teamManager = new TeamManager();
|
private final TeamManager teamManager = new TeamManager();
|
||||||
private NameplateManager nameplateManager = null;
|
private NameplateManager nameplateManager = null;
|
||||||
|
|
||||||
|
private static boolean papiHook = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
instance = this;
|
instance = this;
|
||||||
config = new NJNConfig(this);
|
config = new NJNConfig(this);
|
||||||
|
papiHook = Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null && Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI");
|
||||||
|
|
||||||
DefaultPermissions.registerPermission("notjustnameplates.seeown", "Allows a player to see their own nameplate", PermissionDefault.FALSE);
|
DefaultPermissions.registerPermission("notjustnameplates.seeown", "Allows a player to see their own nameplate", PermissionDefault.FALSE);
|
||||||
DefaultPermissions.registerPermission("notjustnameplates.command", "Allows a player to use the /njn command", PermissionDefault.TRUE);
|
DefaultPermissions.registerPermission("notjustnameplates.command", "Allows a player to use the /njn command", PermissionDefault.TRUE);
|
||||||
@@ -52,6 +55,7 @@ public final class NotJustNameplates extends JavaPlugin {
|
|||||||
|
|
||||||
public void reloadPluginConfig() {
|
public void reloadPluginConfig() {
|
||||||
config = new NJNConfig(this);
|
config = new NJNConfig(this);
|
||||||
|
papiHook = Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null && Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI");
|
||||||
nameplateManager.reloadNameplates();
|
nameplateManager.reloadNameplates();
|
||||||
updateNameplatesBasedOnPermission();
|
updateNameplatesBasedOnPermission();
|
||||||
}
|
}
|
||||||
@@ -92,4 +96,8 @@ public final class NotJustNameplates extends JavaPlugin {
|
|||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isPapiHooked() {
|
||||||
|
return papiHook;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package me.youhavetrouble.notjustnameplates.hooks;
|
||||||
|
|
||||||
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.TextReplacementConfig;
|
||||||
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
|
||||||
|
public class PAPIHook {
|
||||||
|
|
||||||
|
public static Component setPlaceholders(Component component, OfflinePlayer offlinePlayer) {
|
||||||
|
component = component.replaceText(TextReplacementConfig.builder()
|
||||||
|
.match(PlaceholderAPI.getPlaceholderPattern())
|
||||||
|
.replacement((matchResult, builder) -> LegacyComponentSerializer.legacyAmpersand().deserialize(PlaceholderAPI.setPlaceholders(offlinePlayer, matchResult.group(0))))
|
||||||
|
.build());
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package me.youhavetrouble.notjustnameplates.nameplates;
|
|||||||
|
|
||||||
import me.youhavetrouble.notjustnameplates.NotJustNameplates;
|
import me.youhavetrouble.notjustnameplates.NotJustNameplates;
|
||||||
import me.youhavetrouble.notjustnameplates.displays.DisplayContent;
|
import me.youhavetrouble.notjustnameplates.displays.DisplayContent;
|
||||||
|
import me.youhavetrouble.notjustnameplates.hooks.PAPIHook;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@@ -167,6 +168,10 @@ public class Nameplate {
|
|||||||
|
|
||||||
if (player == null || !player.isOnline()) return component;
|
if (player == null || !player.isOnline()) return component;
|
||||||
|
|
||||||
|
if (NotJustNameplates.isPapiHooked()) {
|
||||||
|
component = PAPIHook.setPlaceholders(component, player);
|
||||||
|
}
|
||||||
|
|
||||||
component = component.replaceText(builder -> {
|
component = component.replaceText(builder -> {
|
||||||
builder.matchLiteral("%displayname%");
|
builder.matchLiteral("%displayname%");
|
||||||
builder.replacement(player.displayName());
|
builder.replacement(player.displayName());
|
||||||
|
|||||||
@@ -5,3 +5,6 @@ api-version: "1.20"
|
|||||||
authors: ["YouHaveTrouble"]
|
authors: ["YouHaveTrouble"]
|
||||||
description: Nameplates using display entities
|
description: Nameplates using display entities
|
||||||
website: https://youhavetrouble.me
|
website: https://youhavetrouble.me
|
||||||
|
dependencies:
|
||||||
|
- name: PlaceholderAPI
|
||||||
|
required: false
|
||||||
|
|||||||
Reference in New Issue
Block a user