Skip to content

Commit 5c6aabd

Browse files
committed
プレスホルダー対応
1 parent 83c723b commit 5c6aabd

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@
7474
<id>jitpack.io</id>
7575
<url>https://jitpack.io</url>
7676
</repository>
77+
<repository>
78+
<id>placeholderapi</id>
79+
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
80+
</repository>
7781
</repositories>
7882

7983
<dependencies>
@@ -138,5 +142,11 @@
138142
<version>2.0.1</version>
139143
<scope>compile</scope>
140144
</dependency>
145+
<dependency>
146+
<groupId>me.clip</groupId>
147+
<artifactId>placeholderapi</artifactId>
148+
<version>2.11.2</version>
149+
<scope>provided</scope>
150+
</dependency>
141151
</dependencies>
142152
</project>

src/main/java/com/github/elic0de/thejpspit/TheJpsPit.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.github.elic0de.thejpspit.config.Settings;
99
import com.github.elic0de.thejpspit.database.Database;
1010
import com.github.elic0de.thejpspit.database.SqLiteDatabase;
11+
import com.github.elic0de.thejpspit.hook.PlaceholderHook;
1112
import com.github.elic0de.thejpspit.leveler.Levels;
1213
import com.github.elic0de.thejpspit.listener.CombatTagger;
1314
import com.github.elic0de.thejpspit.player.PitPlayer;
@@ -25,6 +26,7 @@
2526
import com.github.elic0de.thejpspit.villager.villagers.ShopVillager;
2627
import com.google.gson.Gson;
2728
import com.google.gson.GsonBuilder;
29+
import me.clip.placeholderapi.configuration.PlaceholderAPIConfig;
2830
import net.william278.annotaml.Annotaml;
2931
import org.bukkit.Bukkit;
3032
import org.bukkit.GameRule;
@@ -180,6 +182,9 @@ private void registerHooks() {
180182
if (plugins.getPlugin("Vault") != null) {
181183
this.registerHook(new VaultEconomyHook(this));
182184
}
185+
if (plugins.getPlugin("PlaceholderAPI") != null) {
186+
new PlaceholderHook().register();
187+
}
183188
}
184189

185190
private void createNPCs() {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.github.elic0de.thejpspit.hook;
2+
3+
import com.github.elic0de.thejpspit.TheJpsPit;
4+
import com.github.elic0de.thejpspit.database.Database.RankType;
5+
import com.github.elic0de.thejpspit.player.PitPlayer;
6+
import com.github.elic0de.thejpspit.player.PitPlayerManager;
7+
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
8+
import org.bukkit.OfflinePlayer;
9+
import org.jetbrains.annotations.NotNull;
10+
import org.jetbrains.annotations.Nullable;
11+
12+
public class PlaceholderHook extends PlaceholderExpansion {
13+
14+
@Override
15+
public @NotNull String getIdentifier() {
16+
return "thejpspit";
17+
}
18+
19+
@Override
20+
public @NotNull String getAuthor() {
21+
return "Elic0de";
22+
}
23+
24+
@Override
25+
public @NotNull String getVersion() {
26+
return "2.0";
27+
}
28+
29+
@Override
30+
public String onRequest(@Nullable OfflinePlayer offlinePlayer, @NotNull String params) {
31+
// Ensure the player is online
32+
if (offlinePlayer == null || !offlinePlayer.isOnline()) {
33+
return "Player offline";
34+
}
35+
36+
// Return the requested placeholder
37+
final PitPlayer player = PitPlayerManager.getPitPlayer(offlinePlayer.getPlayer());
38+
return switch (params) {
39+
case "kill_ranking" -> String.valueOf(TheJpsPit.getInstance().getDatabase().getPlayerRanking(player, RankType.KILLS).join()
40+
.orElse(0));
41+
case "kill" -> String.valueOf(player.getKills());
42+
case "level" -> String.valueOf(player.getLevel());
43+
default -> null;
44+
};
45+
}
46+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.github.elic0de.thejpspit.spigot.hook;
2+
3+
public class PlacholderHook {
4+
5+
}

0 commit comments

Comments
 (0)