Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.backtobedrock</groupId>
<artifactId>Rewardslite</artifactId>
<version>3.1.3</version>
<version>3.1.4-papi-SNAPSHOT</version>
<packaging>jar</packaging>

<name>RewardsLite</name>
Expand Down
3 changes: 3 additions & 0 deletions src/com/backtobedrock/rewardslite/Rewardslite.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public final class Rewardslite extends JavaPlugin {
private final Map<UUID, AbstractInterface> openInterfaces = new HashMap<>();
private UpdateChecker updateChecker;

public static boolean PAPI_ENABLED = false;

//configurations
private Commands commands;
private Configurations configurations;
Expand Down Expand Up @@ -96,6 +98,7 @@ private void initializeDependencies() {
//PAPI
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
new PlaceholdersRewardsLite().register();
PAPI_ENABLED = true;
}

//EssentialsX
Expand Down
2 changes: 1 addition & 1 deletion src/com/backtobedrock/rewardslite/domain/Reward.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public boolean redeemReward(Player player, boolean manual) {
put("player", player.getName());
put("player_uuid", player.getUniqueId().toString());
}};
this.rewards.forEach(r -> Bukkit.getScheduler().runTask(this.plugin, () -> Bukkit.dispatchCommand(Bukkit.getServer().getConsoleSender(), MessageUtils.replacePlaceholders(r, placeholders))));
this.rewards.forEach(r -> Bukkit.getScheduler().runTask(this.plugin, () -> Bukkit.dispatchCommand(Bukkit.getServer().getConsoleSender(), MessageUtils.replaceAllPlaceholders(player, r, placeholders))));

this.notify(player);
return true;
Expand Down
10 changes: 10 additions & 0 deletions src/com/backtobedrock/rewardslite/utilities/MessageUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.backtobedrock.rewardslite.Rewardslite;
import com.backtobedrock.rewardslite.domain.enumerations.MinecraftVersion;
import com.backtobedrock.rewardslite.domain.enumerations.TimePattern;
import me.clip.placeholderapi.PlaceholderAPI;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;
Expand Down Expand Up @@ -133,6 +135,14 @@ public static String getTimeFromTicks(long amount, TimePattern pattern) {
return sb.toString();
}

public static String replaceAllPlaceholders(Player player, String text, Map<String, String> internalPlaceholders) {
String result = replacePlaceholders(text, internalPlaceholders);
if (Rewardslite.PAPI_ENABLED) {
result = PlaceholderAPI.setPlaceholders(player, result);
}
return result;
}

public static String replacePlaceholders(String string, Map<String, String> placeholders) {
for (Map.Entry<String, String> entry : placeholders.entrySet()) {
string = string.replaceAll("%" + entry.getKey().toLowerCase() + "%", entry.getValue());
Expand Down