Yousuf Company

About one piece haki system

Kodari AI
KodariFri at 9:43 am 1
HakiSystem
A comprehensive One Piece-inspired Haki system plugin for Minecraft. Implements three distinct Haki types: Kenbunshoku (Observation) providing enhanced combat awareness and dodge mechanics, Busoshoku (Armament) granting damage bonuses and defensive hardening, and Haoshoku (Conqueror's) enabling intimidation and crowd control. Features progressive leveling through combat experience, configurable abilities per Haki tier, visual particle effects, cooldown management, and boss bar displays. Players unlock abilities through skill trees, with commands for admin control, GUI-based progression viewing, and full configuration files for balancing all Haki attributes, experience rates, and effect durations.
  • Add toggleable Armament and Observation Haki, plus an activated Conqueror’s Haki ability.

  • Make their effects and cooldowns configurable, with permissions for each ability.

Created a One Piece-inspired Haki plugin:

  • /haki armament boosts melee damage.

  • /haki observation gives a chance to dodge attacks.

  • /haki conqueror weakens nearby targets.

Effects and cooldowns are configurable in config.yml.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
4 167
src/main/java/com/kodari/haki/HakiPlugin.java
package com.kodari.haki;

import com.cryptomorin.xseries.XPotion;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

public final class HakiPlugin extends JavaPlugin implements Listener {
    private final Set<UUID> armament = new HashSet<>();
    private final Set<UUID> observation = new HashSet<>();
    private final Map<UUID, Long> dodgeCooldowns = new HashMap<>();
    private final Map<UUID, Long> conquerorCooldowns = new HashMap<>();

    @Override
    public void onEnable() {
        saveDefaultConfig();
        getServer().getPluginManager().registerEvents(this, this);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player)) {
            sender.sendMessage("Only players can use Haki.");
            return true;
        }
        Player player = (Player) sender;
        if (args.length != 1) {
            player.sendMessage(ChatColor.GOLD + "Usage: /haki <armament|observation|conqueror>");
            return true;
        }
        String ability = args[0].toLowerCase(Locale.ROOT);
        if (!ability.equals("armament") && !ability.equals("observation") && !ability.equals("conqueror")) {
            player.sendMessage(ChatColor.RED + "Unknown Haki type. Use armament, observation, or conqueror.");
            return true;
        }
        if (!player.hasPermission("haki." + ability)) {
            player.sendMessage(ChatColor.RED + "You cannot use that Haki.");
            return true;
        }
        if (ability.equals("conqueror")) {
            useConqueror(player);
        } else {
            Set<UUID> active = ability.equals("armament") ? armament : observation;
            boolean enabled = active.add(player.getUniqueId());
            if (!enabled) active.remove(player.getUniqueId());
            player.sendMessage(ChatColor.GOLD + ability.substring(0, 1).toUpperCase(Locale.ROOT)
                    + ability.substring(1) + " Haki " + (enabled ? "enabled." : "disabled."));
        }
        return true;
    }

    private void useConqueror(Player player) {
        long now = System.currentTimeMillis();
        long ready = conquerorCooldowns.getOrDefault(player.getUniqueId(), 0L);
        if (ready > now) {
            player.sendMessage(ChatColor.RED + "Conqueror's Haki is on cooldown for " + ((ready - now + 999) / 1000) + " seconds.");
            return;
        }
        long seconds = Math.max(0, getConfig().getLong("conqueror.cooldown-seconds", 60));
        conquerorCooldowns.put(player.getUniqueId(), now + seconds * 1000L);
        double radius = Math.max(0, getConfig().getDouble("conqueror.radius", 8.0));
        int weakness = Math.max(0, getConfig().getInt("conqueror.weakness-seconds", 5)) * 20;
        int slowness = Math.max(0, getConfig().getInt("conqueror.slowness-seconds", 5)) * 20;
        int affected = 0;
        for (Entity entity : player.getNearbyEntities(radius, radius, radius)) {
            if (!(entity instanceof LivingEntity) || entity.getLocation().distanceSquared(player.getLocation()) > radius * radius) continue;
            LivingEntity target = (LivingEntity) entity;
            if (target instanceof Player && !player.getWorld().getPVP()) continue;
            if (weakness > 0) XPotion.matchXPotion("WEAKNESS").map(p -> p.buildPotionEffect(weakness, 0)).ifPresent(target::addPotionEffect);
            if (slowness > 0) XPotion.matchXPotion("SLOWNESS").map(p -> p.buildPotionEffect(slowness, 0)).ifPresent(target::addPotionEffect);
            affected++;
        }
        player.sendMessage(ChatColor.GOLD + "You unleash Conqueror's Haki, affecting " + affected + " nearby targets!");
    }

    @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
    public void onCombat(EntityDamageByEntityEvent event) {
        if (event.getEntity() instanceof Player) {
            Player target = (Player) event.getEntity();
            UUID id = target.getUniqueId();
            long now = System.currentTimeMillis();
            double chance = Math.max(0.0, Math.min(1.0, getConfig().getDouble("observation.dodge-chance", 0.25)));
            if (observation.contains(id) && target.hasPermission("haki.observation")
                    && dodgeCooldowns.getOrDefault(id, 0L) <= now && ThreadLocalRandom.current().nextDouble() < chance) {
                event.setCancelled(true);
                long seconds = Math.max(0, getConfig().getLong("observation.cooldown-seconds", 5));
                dodgeCooldowns.put(id, now + seconds * 1000L);
                target.sendMessage(ChatColor.AQUA + "Observation Haki lets you dodge the attack!");
                return;
            }
        }
        if (event.getDamager() instanceof Player) {
            Player attacker = (Player) event.getDamager();
            if (armament.contains(attacker.getUniqueId()) && attacker.hasPermission("haki.armament")) {
                event.setDamage(event.getDamage() * Math.max(0.0, getConfig().getDouble("armament.damage-multiplier", 1.5)));
            }
        }
    }

    @EventHandler
    public void onQuit(PlayerQuitEvent event) {
        UUID id = event.getPlayer().getUniqueId();
        armament.remove(id);
        observation.remove(id);
    }
}