Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add/recipes placeholders #37

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,14 @@
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.expansion.Configurable;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.*;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static com.extendedclip.papi.expansion.player.PlayerUtil.durability;
import static com.extendedclip.papi.expansion.player.PlayerUtil.format12;
import static com.extendedclip.papi.expansion.player.PlayerUtil.format24;
import static com.extendedclip.papi.expansion.player.PlayerUtil.getBiome;
import static com.extendedclip.papi.expansion.player.PlayerUtil.getCapitalizedBiome;
import static com.extendedclip.papi.expansion.player.PlayerUtil.getEmptySlots;
import static com.extendedclip.papi.expansion.player.PlayerUtil.getDirection;
import static com.extendedclip.papi.expansion.player.PlayerUtil.getTotalExperience;
import static com.extendedclip.papi.expansion.player.PlayerUtil.getXZDirection;
import static com.extendedclip.papi.expansion.player.PlayerUtil.itemInHand;

import static com.extendedclip.papi.expansion.player.PlayerUtil.*;

public final class PlayerExpansion extends PlaceholderExpansion implements Configurable {
private String low;
Expand Down Expand Up @@ -195,6 +181,18 @@ public String onRequest(OfflinePlayer player, String identifier) {
return "0";
}

if (identifier.startsWith("has_unlocked_recipe_")) {
if (identifier.split("has_unlocked_recipe_").length > 1) {
String recipeName = identifier.split("has_unlocked_recipe_")[1];
try {
return bool(p.hasDiscoveredRecipe(NamespacedKey.minecraft(recipeName)));
} catch (IllegalArgumentException e) {
return "invalid recipe"; // could be false instead
}
}
return bool(false);
}

if (identifier.startsWith("locale")) {
String localeStr = PlayerUtil.getLocale(p);
String localeStrISO = localeStr.replace("_", "-");
Expand Down Expand Up @@ -223,6 +221,9 @@ public String onRequest(OfflinePlayer player, String identifier) {
}

switch (identifier) {
case "recipes_list":
return p.getDiscoveredRecipes().toString(); // sort of ugly (i dont see the use case either)

case "absorption": {
if (VersionHelper.HAS_ABSORPTION_METHODS) {
return Integer.toString((int) p.getAbsorptionAmount());
Expand Down