SITE XGamer

When you start a world every player gets a single apple and every single apple has a chance to be mutation apple that make player weak when it's day time and turn into a werewolf at night monster don't attack you but iron golem do you get stronger for every blood you get you can get blood from killing humanoid mobs like players villager wondering trader and witch every 15 blood you open your skill tree where you can buy ability for bloods and you can cure your self by crafting a cure apple or finding the doctor villager that sale cure apple you turn human in day monster at night but when cure your normal player

Kodari AI
KodariNov 11 at 12:50 pm 3
WerewolfCursePlugin
Transforms every player into a werewolf at night, gaining strength from blood collected by killing humanoid mobs like players, villagers, wandering traders, and witches. Daytime weakens werewolves, but monsters ignore them while iron golems attack. Every 15 blood unlocks a skill tree to purchase abilities. Players can cure themselves by crafting a cure apple or buying one from a doctor villager, returning to normal human gameplay permanently.

Created Werewolf Apples with mutation chances, blood progression, a skill tree, craftable cure apples, and doctor villagers.

Use /blood to check progress and /skills to open the tree after collecting 15 blood. Mutation and doctor chances are configurable.

Werewolf form grants gameplay effects but does not change the player’s appearance.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
5 325
src/main/java/com/kodari/werewolf/WerewolfApples.java
package com.kodari.werewolf;

import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XPotion;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.IronGolem;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.entity.Villager;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.MerchantRecipe;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffectType;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;

public final class WerewolfApples extends JavaPlugin implements Listener {
    private NamespacedKey starterKey, infectedKey, bloodKey, totalKey, skillsKey, cureKey, doctorKey;
    private static final Set<String> BLOOD_MOBS = Set.of("PLAYER", "VILLAGER", "WANDERING_TRADER", "WITCH", "ZOMBIE", "ZOMBIE_VILLAGER", "HUSK", "DROWNED", "PILLAGER", "VINDICATOR", "EVOKER", "ILLUSIONER", "PIGLIN", "PIGLIN_BRUTE", "ZOMBIFIED_PIGLIN");
    private static final String[] SKILL_NAMES = {"Savage Claws", "Swift Hunt", "Thick Hide"};
    private static final int[] COSTS = {10, 20, 30};
    private static final int[] SLOTS = {11, 13, 15};

    @Override
    public void onEnable() {
        saveDefaultConfig();
        starterKey = new NamespacedKey(this, "starter_received");
        infectedKey = new NamespacedKey(this, "infected");
        bloodKey = new NamespacedKey(this, "blood");
        totalKey = new NamespacedKey(this, "total_blood");
        skillsKey = new NamespacedKey(this, "skills");
        cureKey = new NamespacedKey(this, "cure_apple");
        doctorKey = new NamespacedKey(this, "doctor");
        getServer().getPluginManager().registerEvents(this, this);
        ShapedRecipe recipe = new ShapedRecipe(new NamespacedKey(this, "cure_apple"), cureApple());
        recipe.shape("GEG", "EAE", "GEG");
        recipe.setIngredient('G', material("GOLD_INGOT"));
        recipe.setIngredient('E', material("EMERALD"));
        recipe.setIngredient('A', material("APPLE"));
        getServer().addRecipe(recipe);
        getServer().getScheduler().runTaskTimer(this, this::updateForms, 1L, 60L);
        for (Player player : Bukkit.getOnlinePlayers()) giveStarter(player);
    }

    private Material material(String name) {
        return XMaterial.matchXMaterial(name).map(XMaterial::parseMaterial)
                .orElseThrow(() -> new IllegalStateException("Missing material " + name));
    }

    private ItemStack cureApple() {
        ItemStack item = new ItemStack(material("GOLDEN_APPLE"));
        ItemMeta meta = item.getItemMeta();
        meta.setDisplayName(ChatColor.GREEN + "Cure Apple");
        meta.setLore(List.of(ChatColor.GRAY + "Eat to cure lycanthropy."));
        meta.getPersistentDataContainer().set(cureKey, PersistentDataType.BYTE, (byte) 1);
        item.setItemMeta(meta);
        return item;
    }

    private int value(Player player, NamespacedKey key) {
        return player.getPersistentDataContainer().getOrDefault(key, PersistentDataType.INTEGER, 0);
    }

    private void set(Player player, NamespacedKey key, int value) {
        player.getPersistentDataContainer().set(key, PersistentDataType.INTEGER, value);
    }

    private boolean infected(Player player) {
        return value(player, infectedKey) == 1;
    }

    private boolean night(Player player) {
        long time = player.getWorld().getTime();
        return time >= 13000 && time < 23000;
    }

    private boolean wolf(Player player) {
        return infected(player) && night(player);
    }

    private void giveStarter(Player player) {
        PersistentDataContainer data = player.getPersistentDataContainer();
        if (data.has(starterKey, PersistentDataType.BYTE)) return;
        data.set(starterKey, PersistentDataType.BYTE, (byte) 1);
        for (ItemStack left : player.getInventory().addItem(new ItemStack(material("APPLE"))).values()) {
            player.getWorld().dropItemNaturally(player.getLocation(), left);
        }
        player.sendMessage(ChatColor.GOLD + "You received an apple. Some apples carry a mysterious mutation..." );
    }

    @EventHandler
    public void onJoin(PlayerJoinEvent event) {
        giveStarter(event.getPlayer());
    }

    @EventHandler
    public void onConsume(PlayerItemConsumeEvent event) {
        Player player = event.getPlayer();
        ItemStack item = event.getItem();
        ItemMeta meta = item.getItemMeta();
        if (meta != null && meta.getPersistentDataContainer().has(cureKey, PersistentDataType.BYTE)) {
            if (infected(player)) {
                set(player, infectedKey, 0);
                set(player, bloodKey, 0);
                set(player, totalKey, 0);
                set(player, skillsKey, 0);
                clearEffects(player);
                player.sendMessage(ChatColor.GREEN + "The cure removes your lycanthropy and blood powers.");
            } else player.sendMessage(ChatColor.GRAY + "You are already human.");
        } else if (item.getType() == material("APPLE") && !infected(player)
                && ThreadLocalRandom.current().nextDouble() < chance("mutation-chance")) {
            set(player, infectedKey, 1);
            player.sendMessage(ChatColor.RED + "The apple mutates you! You will become a werewolf at night.");
            applyForm(player);
        }
    }

    private double chance(String path) {
        return Math.max(0.0, Math.min(1.0, getConfig().getDouble(path, 0.1)));
    }

    private void effect(Player player, String name, int amplifier) {
        XPotion.matchXPotion(name).map(potion -> potion.buildPotionEffect(100, amplifier)).ifPresent(player::addPotionEffect);
    }

    private void clearEffects(Player player) {
        for (String name : List.of("WEAKNESS", "STRENGTH", "SPEED", "RESISTANCE")) {
            XPotion.matchXPotion(name).ifPresent(potion -> {
                PotionEffectType type = potion.getPotionEffectType();
                if (type != null) player.removePotionEffect(type);
            });
        }
    }

    private void applyForm(Player player) {
        if (!infected(player)) return;
        if (!night(player)) {
            effect(player, "WEAKNESS", 0);
            return;
        }
        int total = value(player, totalKey);
        int skills = value(player, skillsKey);
        effect(player, "STRENGTH", Math.min(4, total / 15 + ((skills & 1) != 0 ? 1 : 0)));
        effect(player, "SPEED", (skills & 2) != 0 ? 1 : 0);
        if ((skills & 4) != 0) effect(player, "RESISTANCE", 0);
    }

    private void updateForms() {
        for (Player player : Bukkit.getOnlinePlayers()) {
            if (!infected(player)) continue;
            applyForm(player);
            if (!wolf(player)) continue;
            for (Entity entity : player.getNearbyEntities(16, 8, 16)) {
                if (entity instanceof IronGolem golem && golem.hasLineOfSight(player)
                        && (golem.getTarget() == null || golem.getTarget().isDead())) golem.setTarget(player);
            }
        }
    }

    @EventHandler
    public void onTarget(EntityTargetLivingEntityEvent event) {
        if (event.getEntity() instanceof Monster && event.getTarget() instanceof Player player && wolf(player)) {
            event.setCancelled(true);
        }
    }

    @EventHandler
    public void onDeath(EntityDeathEvent event) {
        Player killer = event.getEntity().getKiller();
        if (killer == null || !wolf(killer) || !BLOOD_MOBS.contains(event.getEntityType().name())) return;
        int blood = value(killer, bloodKey) + 1;
        int total = value(killer, totalKey) + 1;
        set(killer, bloodKey, blood);