Skip to content

Commit

Permalink
Merge pull request #8 from XXY233/placeholder-api-support
Browse files Browse the repository at this point in the history
add papi support
  • Loading branch information
SchnTgaiSpock authored Sep 29, 2023
2 parents 95b8653 + c2bb937 commit b6dc2d5
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ The HUD lets you see what Slimefun item a block is without breaking or opening i

<https://user-images.githubusercontent.com/101147426/182007545-474a6596-b4e2-4a92-bdab-c18ed2286a94.mp4>

## PlaceholderAPI

- `%slimehud_toggle%`
Returns the current player's toggle state. Possible values are `true` or `false`.

## Limitations

- Minecraft only has 7 colors for the bossbar, compared to 16 for regular items.
Expand Down
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>

<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>

<build>
Expand Down Expand Up @@ -109,6 +114,13 @@
<scope>compile</scope>
</dependency>

<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.11.4</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/github/schntgaispock/slimehud/SlimeHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import javax.annotation.Nonnull;

import io.github.schntgaispock.slimehud.placeholder.PlaceholderManager;
import io.github.schntgaispock.slimehud.waila.HudController;
import org.bstats.bukkit.Metrics;
import org.bstats.charts.SimplePie;
Expand Down Expand Up @@ -48,6 +49,7 @@ public void enable() {

WAILAManager.setup();
CommandManager.setup();
PlaceholderManager.setup();
hudController = new HudController();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.github.schntgaispock.slimehud.placeholder;

import io.github.schntgaispock.slimehud.SlimeHUD;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.entity.Player;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class PlaceholderHook extends PlaceholderExpansion {
@Override
public @Nonnull String getIdentifier() {
return "slimehud";
}

@Override
public @Nonnull String getAuthor() {
return "TheLittle_Yang";
}

@Override
public @Nonnull String getVersion() {
return "1.0.0";
}

@Override
public boolean persist() {
return true;
}

@Override
public @Nullable String onPlaceholderRequest(Player player, @Nonnull String params) {
if (params.equalsIgnoreCase("toggle")) {
return SlimeHUD.getInstance().getPlayerData().getString(player.getUniqueId() + ".waila", "true");
} else {
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.github.schntgaispock.slimehud.placeholder;

import io.github.schntgaispock.slimehud.SlimeHUD;
import org.bukkit.Bukkit;

public class PlaceholderManager {
public static void setup() {
if (SlimeHUD.getInstance().getConfig().getBoolean("options.placeholder-api-support", true)) {
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
new PlaceholderHook().register();
} else {
SlimeHUD.getInstance().getLogger().info("PlaceholderAPI is not installed and has been ignored.");
}
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ options:

auto-update: true

# Use PlaceholderAPI to get the player's toggle status
placeholder-api-support: true

waila:

Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ api-version: 1.14
depend:
- Slimefun

softdepend:
- PlaceholderAPI

commands:
slimehud:
description: /slimehud
Expand Down

0 comments on commit b6dc2d5

Please sign in to comment.