-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: parses placeholders in commands using PAPI
Closes #70
- Loading branch information
1 parent
24039b5
commit 5027f6a
Showing
5 changed files
with
60 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/me/roinujnosde/titansbattle/hooks/papi/PlaceholderHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package me.roinujnosde.titansbattle.hooks.papi; | ||
|
||
import me.clip.placeholderapi.PlaceholderAPI; | ||
import me.roinujnosde.titansbattle.TitansBattle; | ||
import me.roinujnosde.titansbattle.types.Warrior; | ||
import org.bukkit.OfflinePlayer; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class PlaceholderHook { | ||
|
||
private final TitansBattle plugin; | ||
|
||
public PlaceholderHook(@NotNull TitansBattle plugin) { | ||
this.plugin = plugin; | ||
if (isPapi()) { | ||
new TBExpansion(plugin).register(); | ||
} | ||
} | ||
|
||
public String parse(@Nullable OfflinePlayer player, @NotNull String text, String... internalPlaceholders) { | ||
for (int i = 0; i + 1 < internalPlaceholders.length; i = i + 2) { | ||
text = text.replace(internalPlaceholders[i], internalPlaceholders[i + 1]); | ||
} | ||
if (isPapi()) { | ||
return PlaceholderAPI.setPlaceholders(player, text); | ||
} | ||
return text; | ||
} | ||
|
||
public String parse(@NotNull Warrior warrior, @NotNull String text, String... internalPlaceholders) { | ||
return parse(warrior.toPlayer(), text, internalPlaceholders); | ||
} | ||
|
||
public boolean isPapi() { | ||
return plugin.getServer().getPluginManager().isPluginEnabled("PlaceholderAPI"); | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...nosde/titansbattle/hooks/TBExpansion.java → .../titansbattle/hooks/papi/TBExpansion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters