filip jancar

Create a lightweight Minecraft plugin called RivexWanted for Paper 26.2 using Java 25. Every configurable interval, randomly select an online player as the WANTED target and broadcast an announcement to the entire server. Display their name, head, and bounty reward on a configurable wanted poster at spawn. Players who kill the wanted target receive the bounty through Vault. Add configurable selection intervals, bounty amounts, minimum online players, cooldowns, GUI or hologram support, YAML configuration, admin commands, permissions, and persistent data. Prevent exploits such as self-kills, kill farming, and repeated bounty claims. Make the plugin optimized, easy to configure, and compatible with PlaceholderAPI.

Kodari AI
KodariNov 3 at 2:32 pm 4
RivexWanted
A lightweight Paper plugin that randomly selects an online player as a WANTED target at configurable intervals, broadcasting announcements server-wide. Displays the target's name, head, and bounty on a configurable spawn poster. Kills award bounty rewards through Vault with anti-exploit protections against self-kills, kill farming, and repeated claims. Features YAML configuration, admin commands, permissions, GUI/hologram support, PlaceholderAPI compatibility, and persistent data storage for optimized, easy configuration.
  1. Create scheduled wanted selection, persistent cooldowns, and guarded Vault payouts.

  2. Add a configurable spawn poster GUI, admin commands, and PlaceholderAPI support.

Created RivexWanted with scheduled selection, Vault payouts, persistent cooldowns, and a configurable poster GUI.

  • Use /wanted setposter while looking at a spawn block; players can right-click it or use /wanted.

  • Admin commands: /wanted select, /wanted clear, and /wanted reload.

  • PlaceholderAPI: %rivexwanted_target%, %rivexwanted_reward%, %rivexwanted_active%, and %rivexwanted_next_selection%.

Vault and an economy provider are required. Cooldowns reduce repeat farming, but cannot prevent all collusion.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
6 423
src/main/java/com/rivexwanted/RivexWanted.java
package com.rivexwanted;

import com.cryptomorin.xseries.XMaterial;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

public final class RivexWanted extends JavaPlugin implements Listener {
    private Economy economy;
    private UUID target;
    private String targetName;
    private double reward;
    private long nextSelection;
    private final Map<String, Long> targetCooldowns = new HashMap<>();
    private final Map<String, Long> killerCooldowns = new HashMap<>();
    private final Map<String, Long> pairCooldowns = new HashMap<>();
    private Location poster;
    private File dataFile;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        RegisteredServiceProvider<Economy> provider = getServer().getServicesManager().getRegistration(Economy.class);
        if (provider == null || provider.getProvider() == null) {
            getLogger().severe("Vault has no economy provider; disabling RivexWanted.");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }
        economy = provider.getProvider();
        dataFile = new File(getDataFolder(), "data.yml");
        if (!loadData()) {
            getLogger().severe("Could not load persistent data safely; disabling RivexWanted.");
            getServer().getPluginManager().disablePlugin(this);
            return;
        }
        getServer().getPluginManager().registerEvents(this, this);
        if (getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")) {
            new WantedExpansion(this).register();
        }
        getServer().getScheduler().runTaskTimer(this, () -> {
            if (System.currentTimeMillis() >= nextSelection) selectTarget();
        }, 20L, 20L);
    }

    private boolean loadData() {
        YamlConfiguration data = new YamlConfiguration();
        if (dataFile.exists()) {
            try { data.load(dataFile); } catch (Exception e) {
                getLogger().severe("Failed to read data.yml: " + e.getMessage());
                return false;
            }
        }
        try {
            String id = data.getString("target.uuid");
            if (id != null) {
                target = UUID.fromString(id);
                targetName = data.getString("target.name", "Unknown");
                reward = data.getDouble("target.reward");
                if (!Double.isFinite(reward) || reward <= 0) throw new IllegalArgumentException("Invalid saved bounty");
            }
            nextSelection = data.getLong("next-selection", System.currentTimeMillis() + intervalMillis());
            readCooldowns(data.getConfigurationSection("cooldowns.target"), targetCooldowns);
            readCooldowns(data.getConfigurationSection("cooldowns.killer"), killerCooldowns);
            readCooldowns(data.getConfigurationSection("cooldowns.pair"), pairCooldowns);
            poster = data.getLocation("poster");
            return true;
        } catch (Exception e) {
            getLogger().severe("Invalid data.yml: " + e.getMessage());
            return false;
        }
    }

    private void readCooldowns(ConfigurationSection section, Map<String, Long> map) {
        if (section == null) return;
        long now = System.currentTimeMillis();
        for (String key : section.getKeys(false)) {
            long expires = section.getLong(key);
            if (expires > now) map.put(key, expires);
        }
    }

    private boolean saveData() {
        long now = System.currentTimeMillis();
        targetCooldowns.values().removeIf(t -> t <= now);
        killerCooldowns.values().removeIf(t -> t <= now);
        pairCooldowns.values().removeIf(t -> t <= now);
        YamlConfiguration data = new YamlConfiguration();
        if (target != null) {
            data.set("target.uuid", target.toString());
            data.set("target.name", targetName);
            data.set("target.reward", reward);
        }
        data.set("next-selection", nextSelection);
        data.set("poster", poster);
        targetCooldowns.forEach((key, value) -> data.set("cooldowns.target." + key, value));
        killerCooldowns.forEach((key, value) -> data.set("cooldowns.killer." + key, value));
        pairCooldowns.forEach((key, value) -> data.set("cooldowns.pair." + key, value));
        File temporary = new File(getDataFolder(), "data.yml.tmp");
        try {
            data.save(temporary);
            try {
                Files.move(temporary.toPath(), dataFile.toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
            } catch (java.nio.file.AtomicMoveNotSupportedException ex) {
                Files.move(temporary.toPath(), dataFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
            }
            return true;
        } catch (IOException e) {
            getLogger().severe("Could not save wanted data; disabling plugin to prevent duplicate claims: " + e.getMessage());
            getServer().getPluginManager().disablePlugin(this);
            return false;
        }
    }

    private long intervalMillis() {
        return Math.max(1L, Math.min(31536000L, getConfig().getLong("selection-interval", 1800))) * 1000L;
    }

    private long cooldown(String name) {
        return Math.max(0L, Math.min(31536000L, getConfig().getLong("cooldowns." + name, 0))) * 1000L;
    }

    private void selectTarget() {
        long now = System.currentTimeMillis();
        nextSelection = now + intervalMillis();
        List<Player> eligible = new ArrayList<>();
        if (Bukkit.getOnlinePlayers().size() >= Math.max(1, getConfig().getInt("minimum-online", 2))) {
            for (Player player : Bukkit.getOnlinePlayers()) {
                if (!player.getUniqueId().equals(target) && targetCooldowns.getOrDefault(player.getUniqueId().toString(), 0L) <= now) eligible.add(player);
            }
        }
        double amount = getConfig().getDouble("bounty", 1000.0);
        if (!Double.isFinite(amount) || amount <= 0) {
            getLogger().warning("Bounty must be a finite positive number; selection skipped.");
            saveData();
            return;
        }
        if (eligible.isEmpty()) {
            saveData();
            return;
        }
        Player chosen = eligible.get(ThreadLocalRandom.current().nextInt(eligible.size()));
        target = chosen.getUniqueId();
        targetName = chosen.getName();
        reward = amount;
        targetCooldowns.put(target.toString(), now + cooldown("target"));
        if (saveData()) broadcast("selected", null, targetName, reward);
    }

    @EventHandler
    public void onDeath(PlayerDeathEvent event) {
        Player victim = event.getEntity();
        if (target == null || !target.equals(victim.getUniqueId())) return;
        Player killer = victim.getKiller();
        String victimId = target.toString();
        String name = targetName;
        double amount = reward;
        long now = System.currentTimeMillis();
        String killerId = killer == null ? "" : killer.getUniqueId().toString();
        String pair = killerId + "_" + victimId;
        boolean valid = killer != null && !killer.getUniqueId().equals(target)
                && killerCooldowns.getOrDefault(killerId, 0L) <= now
                && pairCooldowns.getOrDefault(pair, 0L) <= now;
        target = null;
        targetName = null;
        reward = 0;
        if (valid) {