Skip to content

Commit

Permalink
Add PlaceholderAPI support
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverSchlueter committed Mar 20, 2023
1 parent e579a87 commit aa3f0cd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
7 changes: 6 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
}

repositories {
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
}

dependencies {
paperDevBundle("1.19.4-R0.1-SNAPSHOT")
compileOnly("me.clip:placeholderapi:2.11.3")
paperweight.paperDevBundle("1.19.4-R0.1-SNAPSHOT")
}

tasks {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/de/oliver/FancyHolograms.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class FancyHolograms extends JavaPlugin {

private final HologramManager hologramManager;
private boolean muteVersionNotification;
private boolean usingPlaceholderApi;

public FancyHolograms() {
instance = this;
Expand All @@ -37,6 +38,8 @@ public void onEnable() {

PluginManager pluginManager = Bukkit.getPluginManager();

usingPlaceholderApi = pluginManager.getPlugin("PlaceholderAPI") != null;

new Thread(() -> {
ComparableVersion newestVersion = VersionFetcher.getNewestVersion();
ComparableVersion currentVersion = new ComparableVersion(getDescription().getVersion());
Expand Down Expand Up @@ -112,6 +115,10 @@ public boolean isMuteVersionNotification() {
return muteVersionNotification;
}

public boolean isUsingPlaceholderApi() {
return usingPlaceholderApi;
}

public static FancyHolograms getInstance() {
return instance;
}
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/de/oliver/Hologram.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.math.Transformation;
import io.papermc.paper.adventure.PaperAdventure;
import me.clip.placeholderapi.PlaceholderAPI;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
Expand All @@ -14,6 +15,7 @@
import net.minecraft.world.level.Level;
import org.bukkit.Location;
import org.bukkit.craftbukkit.v1_19_R3.CraftWorld;
import org.bukkit.entity.Player;
import org.joml.Quaternionf;
import org.joml.Vector3f;

Expand Down Expand Up @@ -76,7 +78,7 @@ public void remove(ServerPlayer serverPlayer) {
}

public void updateText(ServerPlayer serverPlayer){
entity.setText(getText());
entity.setText(getText(serverPlayer.getBukkitEntity()));

if(serverPlayer != null) {
entity.getEntityData().refresh(serverPlayer);
Expand Down Expand Up @@ -124,8 +126,13 @@ public void updateBackground(ServerPlayer serverPlayer){
}
}

private Component getText(){
private Component getText(Player player){
String t = String.join("\n", lines);

if(FancyHolograms.getInstance().isUsingPlaceholderApi()){
t = PlaceholderAPI.setPlaceholders(player, t);
}

return PaperAdventure.asVanilla(MiniMessage.miniMessage().deserialize(t));
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ author: OliverHD
version: 1.0.0
api-version: 1.19
load: POSTWORLD
softdepend:
- PlaceholderAPI
commands:
Hologram:
permission: FancyHolograms.admin
Expand Down

0 comments on commit aa3f0cd

Please sign in to comment.