Walter Rosi
📎 1 file 1,766 chars
📄
pasted-code-1794508538585.txt
txt 2 lines
▶

I would like you to add to this plugin powers named after the seven deadly sins with these features. Pride inflicts weakness 1 on the enemy if you manage to hit the opponent 3 times in a row. The weakness effect will last for 20 seconds with a cooldown of 2 minutes. Let me give an example: I activate the ability, which will stay on 'stand by' until I hit a player 3 times in a row, where on the fourth hit it will apply weakness. When the power of greed is activated, it allows you to use the power of the last enemy you hit. For example, if a player with the sin of wrath was hit last, and I activate the ability of sloth, I can use strength 3 for 20 seconds. The same applies: the cooldown is 2 minutes and the duration is 20 seconds. In the case of wrath, when the player activates the ability, they gain strength 3 for 20 seconds, with a cooldown of 2 minutes. Lust, instead, will double the heart row, from 10 hearts to twenty, but will get slowness 1. These effects will always last 20 seconds and can be recharged in 2 minutes. With sloth, for 20 seconds the player who activated the ability can ignore other people’s effects. For example, if the opponent has resistance 4, greed can ignore it with its power, or if the opponent had strength 2, the player with greed wouldn’t take as much damage as other players. The cooldown is 2 minutes and the duration is 20 seconds. Avarice grants random diamond/gold/iron drops from 7% of kills. Powers are activated with Shift + right-click, with a shield unequipped in the off-hand. The cooldown stays visible in red on the action bar. To give powers, an operator uses the command /power (sin name) (player name) add, and to remove it /power (player name) remove. I’d like the plugin to be for version 26.3 Paper.
Kodari AI
KodariNov 12 at 6:36 pm 4
SevenDeadlySinsPowers
SevenDeadlySinsPowers is a Paper 26.3 plugin that grants players unique combat abilities themed after the seven deadly sins. Each sin power activates via Shift+right-click with an empty off-hand, displaying a red cooldown timer on the action bar. Pride inflicts Weakness I on enemies after three consecutive hits, lasting 20 seconds with a 2-minute cooldown. Wrath grants Strength III for 20 seconds on activation. Greed copies the last-hit enemy's sin power for 20 seconds. Lust doubles max health to 20 hearts but applies Slowness I. Sloth grants immunity to other players' potion effects for 20 seconds. Avarice provides a 7% chance of diamond, gold, or iron drops from kills. All effects last 20 seconds with 2-minute cooldowns. Operators manage powers via /power (sin) (player) add and /power (player) remove commands.
  • Add the six powers described, with operator assignment and persistent player data.

  • Handle activation, cooldowns, combat effects and passive Avarice drops. Greed will copy the last player you hit.

Created the six described powers for Paper 26.3. Avarice is passive; the other powers activate with sneak + right-click when no shield is in the off-hand.

The request names six powers rather than seven, so no seventh power was added.

Kodari can make mistakes. Review important code before using.
Files
src
pom.xml
Code
3 287
src/main/java/ai/kodari/sinpowers/SinPowers.java
package ai.kodari.sinpowers;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

public final class SinPowers extends JavaPlugin implements Listener {
    private enum Sin { PRIDE, GREED, WRATH, LUST, SLOTH, AVARICE }

    private static final long COOLDOWN = 120_000L;
    private static final long DURATION = 20_000L;
    private final Map<UUID, Sin> powers = new HashMap<>();
    private final Map<UUID, Long> cooldowns = new HashMap<>();
    private final Map<UUID, UUID> lastTargets = new HashMap<>();
    private final Map<UUID, UUID> prideTargets = new HashMap<>();
    private final Map<UUID, Integer> prideHits = new HashMap<>();
    private final Map<UUID, Long> slothUntil = new HashMap<>();
    private final Map<UUID, Double> lustHealth = new HashMap<>();

    @Override
    public void onEnable() {
        getConfig().getConfigurationSection("powers");
        if (getConfig().isConfigurationSection("powers")) {
            for (String key : getConfig().getConfigurationSection("powers").getKeys(false)) {
                try {
                    powers.put(UUID.fromString(key), Sin.valueOf(getConfig().getString("powers." + key, "")));
                } catch (IllegalArgumentException ex) {
                    getLogger().warning("Invalid saved power for " + key);
                }
            }
        }
        Bukkit.getPluginManager().registerEvents(this, this);
        Bukkit.getScheduler().runTaskTimer(this, this::tick, 0L, 20L);
    }

    @Override
    public void onDisable() {
        for (UUID id : java.util.List.copyOf(lustHealth.keySet())) {
            Player player = Bukkit.getPlayer(id);
            if (player != null) restoreHealth(player);
        }
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (args.length == 3 && args[2].equalsIgnoreCase("add")) {
            Sin sin;
            try {
                sin = Sin.valueOf(args[0].toUpperCase(Locale.ROOT));
            } catch (IllegalArgumentException ex) {
                sender.sendMessage(Component.text("Unknown power. Choose pride, greed, wrath, lust, sloth or avarice.", NamedTextColor.RED));
                return true;
            }
            Player target = Bukkit.getPlayerExact(args[1]);
            if (target == null) {
                sender.sendMessage(Component.text("The player must be online.", NamedTextColor.RED));
                return true;
            }
            clearState(target);
            powers.put(target.getUniqueId(), sin);
            getConfig().set("powers." + target.getUniqueId(), sin.name());
            saveConfig();
            sender.sendMessage(Component.text("Assigned " + sin.name().toLowerCase(Locale.ROOT) + " to " + target.getName() + ".", NamedTextColor.GREEN));
            target.sendMessage(Component.text("Your power is " + sin.name().toLowerCase(Locale.ROOT) + ".", NamedTextColor.GOLD));
            return true;
        }
        if (args.length == 2 && args[1].equalsIgnoreCase("remove")) {
            OfflinePlayer target = Bukkit.getOfflinePlayer(args[0]);
            UUID id = target.getUniqueId();
            if (!powers.containsKey(id)) {
                sender.sendMessage(Component.text("That player has no assigned power.", NamedTextColor.RED));
                return true;
            }
            Player online = target.getPlayer();
            if (online != null) clearState(online);
            powers.remove(id);
            getConfig().set("powers." + id, null);
            saveConfig();
            sender.sendMessage(Component.text("Removed the power from " + args[0] + ".", NamedTextColor.GREEN));
            return true;
        }
        return false;
    }

    @EventHandler(ignoreCancelled = true)
    public void onInteract(PlayerInteractEvent event) {
        if (event.getHand() != EquipmentSlot.HAND || (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK)) return;
        Player player = event.getPlayer();
        if (!player.isSneaking() || player.getInventory().getItemInOffHand().getType() == Material.SHIELD) return;
        Sin sin = powers.get(player.getUniqueId());
        if (sin == null) return;
        if (sin == Sin.AVARICE) {
            player.sendMessage(Component.text("Avarice is passive: kills have a 7% chance to drop a reward.", NamedTextColor.GOLD));
            return;
        }
        UUID id = player.getUniqueId();
        if (cooldowns.getOrDefault(id, 0L) > System.currentTimeMillis()) return;
        if (sin == Sin.GREED) {
            UUID target = lastTargets.get(id);
            sin = target == null ? null : powers.get(target);
            if (sin == null || sin == Sin.GREED || sin == Sin.AVARICE) {
                player.sendMessage(Component.text("Your last player target has no active power to copy.", NamedTextColor.RED));
                return;
            }
        }
        event.setCancelled(true);
        activate(player, sin);
    }

    private void activate(Player player, Sin sin) {
        UUID id = player.getUniqueId();
        switch (sin) {
            case PRIDE -> {
                prideHits.put(id, 0);
                prideTargets.remove(id);
                player.sendMessage(Component.text("Pride armed: hit the same player four times in a row.", NamedTextColor.GOLD));
                return;
            }
            case WRATH -> player.addPotionEffect(new PotionEffect(PotionEffectType.STRENGTH, 400, 2));
            case LUST -> {
                AttributeInstance attribute = player.getAttribute(Attribute.MAX_HEALTH);
                if (attribute == null) return;
                lustHealth.put(id, attribute.getBaseValue());
                attribute.setBaseValue(attribute.getBaseValue() + 20.0);
                player.addPotionEffect(new PotionEffect(PotionEffectType.SLOWNESS, 400, 0));
                Bukkit.getScheduler().runTaskLater(this, () -> restoreHealth(player), 400L);
            }
            case SLOTH -> slothUntil.put(id, System.currentTimeMillis() + DURATION);
            default -> { return; }
        }
        cooldowns.put(id, System.currentTimeMillis() + COOLDOWN);
        player.sendMessage(Component.text(sin.name().toLowerCase(Locale.ROOT) + " activated for 20 seconds.", NamedTextColor.GOLD));
    }

    @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
    public void onDamage(EntityDamageByEntityEvent event) {
        Player attacker = null;
        boolean melee = event.getDamager() instanceof Player;
        if (event.getDamager() instanceof Player player) attacker = player;
        else if (event.getDamager() instanceof Projectile projectile && projectile.getShooter() instanceof Player player) attacker = player;
        if (attacker == null || !(event.getEntity() instanceof Player victim) || attacker.equals(victim)) return;
        UUID id = attacker.getUniqueId();
        lastTargets.put(id, victim.getUniqueId());

        if (prideHits.containsKey(id)) {
            int hits = victim.getUniqueId().equals(prideTargets.get(id)) ? prideHits.get(id) + 1 : 1;
            prideTargets.put(id, victim.getUniqueId());
            if (hits >= 4) {
                victim.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 400, 0));
                prideHits.remove(id);
                prideTargets.remove(id);
                cooldowns.put(id, System.currentTimeMillis() + COOLDOWN);
                attacker.sendMessage(Component.text("Pride inflicted weakness.", NamedTextColor.GOLD));
            } else prideHits.put(id, hits);
        }

        long now = System.currentTimeMillis();
        if (melee && slothUntil.getOrDefault(victim.getUniqueId(), 0L) > now) {
            PotionEffect strength = attacker.getPotionEffect(PotionEffectType.STRENGTH);
            if (strength != null) event.setDamage(Math.max(0, event.getDamage() - 3.0 * (strength.getAmplifier() + 1)));
        }
        if (slothUntil.getOrDefault(id, 0L) > now && event.isApplicable(EntityDamageEvent.DamageModifier.RESISTANCE)) {
            event.setDamage(EntityDamageEvent.DamageModifier.RESISTANCE, 0.0);
        }
    }

    @EventHandler
    public void onDeath(PlayerDeathEvent event) {
        Player victim = event.getEntity();
        Player killer = victim.getKiller();
        if (killer != null && !killer.equals(victim) && powers.get(killer.getUniqueId()) == Sin.AVARICE && ThreadLocalRandom.current().nextInt(100) < 7) {
            Material[] rewards = {Material.DIAMOND, Material.GOLD_INGOT, Material.IRON_INGOT};
            event.getDrops().add(new ItemStack(rewards[ThreadLocalRandom.current().nextInt(rewards.length)]));