Skip to content

Commit

Permalink
add placeholder api support to Items section
Browse files Browse the repository at this point in the history
  • Loading branch information
ryderbelserion committed Aug 15, 2024
1 parent b51d859 commit 3efb9a3
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/main/java/com/badbones69/crazycrates/api/PrizeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.badbones69.crazycrates.api.events.PlayerPrizeEvent;
import com.badbones69.crazycrates.api.objects.Crate;
import com.badbones69.crazycrates.api.objects.Prize;
import com.ryderbelserion.vital.paper.api.builders.items.ItemBuilder;
import com.badbones69.crazycrates.api.builders.ItemBuilder;
import com.ryderbelserion.vital.paper.api.enums.Support;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.entity.Player;
Expand All @@ -17,7 +17,9 @@
import com.badbones69.crazycrates.api.utils.MiscUtils;
import com.badbones69.crazycrates.api.utils.MsgUtils;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import static java.util.regex.Matcher.quoteReplacement;
Expand Down Expand Up @@ -51,7 +53,27 @@ public static void givePrize(@NotNull final Player player, @Nullable Prize prize
}

if (!prize.getItemBuilders().isEmpty()) {
final boolean isPlaceholderAPIEnabled = Support.placeholder_api.isEnabled();

for (final ItemBuilder item : prize.getItemBuilders()) {
if (isPlaceholderAPIEnabled) {
final String displayName = item.getDisplayName();

if (!displayName.isEmpty()) {
item.setDisplayName(PlaceholderAPI.setPlaceholders(player, displayName));
}

final List<String> displayLore = item.getDisplayLore();

if (!displayLore.isEmpty()) {
List<String> lore = new ArrayList<>();

displayLore.forEach(line -> lore.add(PlaceholderAPI.setPlaceholders(player, line)));

item.setDisplayLore(lore);
}
}

if (!MiscUtils.isInventoryFull(player)) {
MiscUtils.addItem(player, item.setPlayer(player).getStack());
} else {
Expand Down

0 comments on commit 3efb9a3

Please sign in to comment.