<commit_before>package com.elmakers.mine.bukkit.action.builtin;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;

import com.elmakers.mine.bukkit.action.BaseSpellAction;
import com.elmakers.mine.bukkit.api.action.CastContext;
import com.elmakers.mine.bukkit.api.magic.Mage;
import com.elmakers.mine.bukkit.api.magic.Messages;
import com.elmakers.mine.bukkit.api.spell.SpellResult;
import com.elmakers.mine.bukkit.api.wand.Wand;
import com.elmakers.mine.bukkit.utility.ConfigurationUtils;

public class BookAction extends BaseSpellAction {

    @Nonnull
    private String title = "";
    @Nonnull
    private String author = "";
    @Nullable
    private ConfigurationSection pages;
    private boolean giveBook;

    private ItemStack updateBook(CastContext context, Mage targetMage, ItemStack book) {
        BookMeta meta = (BookMeta) book.getItemMeta();

        List<String> pages = replaceContents(context, targetMage);

        meta.setTitle(title);
        meta.setAuthor(author);
        meta.setPages(pages);

        book.setItemMeta(meta);

        return book;
    }

    private static class Replacement {
        public String replace;
        public String with;

        public Replacement(String replace, String with) {
            this.replace = replace;
            this.with = with;
        }
    }

    private List<String> replaceContents(CastContext context, Mage targetMage) {
        List<Replacement> replacements = new ArrayList<>();


        Set<String> attributes = context.getController().getAttributes();
        Set<String> currencies = context.getController().getCurrencyKeys();

        for (String attr : attributes) {
            replacements.add(new Replacement("$" + attr, Integer.toString((int)Math.ceil(targetMage.getAttribute(attr)))));
        }

        for (String currency : currencies) {
            replacements.add(new Replacement("$" + currency, Integer.toString((int)Math.ceil(targetMage.getCurrency(currency)))));
        }

        replacements.add(new Replacement("@tn", targetMage.getName()));
        replacements.add(new Replacement("@td", targetMage.getDisplayName()));
        replacements.add(new Replacement("@p", context.getMage().getName()));
        replacements.add(new Replacement("@pd", context.getMage().getDisplayName()));
<commit_msg>Add mage class and path to Book replacements<commit_after>package com.elmakers.mine.bukkit.action.builtin;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;

import com.elmakers.mine.bukkit.action.BaseSpellAction;
import com.elmakers.mine.bukkit.api.action.CastContext;
import com.elmakers.mine.bukkit.api.magic.Mage;
import com.elmakers.mine.bukkit.api.magic.MageClass;
import com.elmakers.mine.bukkit.api.magic.Messages;
import com.elmakers.mine.bukkit.api.magic.ProgressionPath;
import com.elmakers.mine.bukkit.api.spell.SpellResult;
import com.elmakers.mine.bukkit.api.wand.Wand;
import com.elmakers.mine.bukkit.utility.ConfigurationUtils;

public class BookAction extends BaseSpellAction {

    @Nonnull
    private String title = "";
    @Nonnull
    private String author = "";
    @Nullable
    private ConfigurationSection pages;
    private boolean giveBook;

    private ItemStack updateBook(CastContext context, Mage targetMage, ItemStack book) {
        BookMeta meta = (BookMeta) book.getItemMeta();

        List<String> pages = replaceContents(context, targetMage);

        meta.setTitle(title);
        meta.setAuthor(author);
        meta.setPages(pages);

        book.setItemMeta(meta);

        return book;
    }

    private static class Replacement {
        public String replace;
        public String with;

        public Replacement(String replace, String with) {
            this.replace = replace;
            this.with = with;
        }
    }

    private List<String> replaceContents(CastContext context, Mage targetMage) {
        List<Replacement> replacements = new ArrayList<>();


        Set<String> attributes = context.getController().getAttributes();
        Set<String> currencies = context.getController().getCurrencyKeys();

        for (String attr : attributes) {
            replacements.add(new Replacement("$" + attr, Integer.toString((int)Math.ceil(targetMage.getAttribute(attr)))));
        }

        for (String currency : currencies) {
            replacements.add(new Replacement("$" + currency, Integer.toString((int)Math.ceil(targetMage.getCurrency(currency)))));
        }

        replacements.add(new Replacement("@tn", targetMage.getName()));
        replacements.add(new Replacement("@td", targetMage.getDisplayName()));
        replacements.add(new Replacement("@p", context.getMage().getName()));
        replacements.add(new Replacement("@pd", context.getMage().getDisplayName()));

        MageClass mageClass = targetMage.getActiveClass();
        String className = mageClass != null ? mageClass.getName() : "";
        ProgressionPath magePath = targetMage.getActiveProperties().getPath();
        String pathName = magePath != null ? magePath.getName() : "";

        replacements.add(new Replacement("$class", className));
        replacements.add(new Replacement("$path", pathName));

{'fraction_non_alphanumeric': 0.11688963210702341, 'fraction_numerical': 0.0, 'mean_word_length': 3.7430610626486915, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1696638', 'n_tokens_mistral': 1764, 'n_tokens_neox': 1697, 'n_words': 327}