Abbas Gaming

Yerha prompt

This plugin introduces a legendary PvP item called the Sunrise Card (textured via Custom Model Data). It grants devastating abilities when used during combat, allowing players to dominate PvP encounters.

Kodari AI
KodariOct 11 at 2:57 am 1
SunriseCard
A Minecraft plugin introducing a legendary PvP item called the Sunrise Card, textured via Custom Model Data. This powerful artifact grants devastating combat abilities when activated during PvP encounters, allowing players to dominate battles. The plugin includes item crafting recipes, cooldown management, particle effects, sound effects, and configurable ability parameters. Players can obtain the card through crafting or commands, and activate its unique abilities to gain temporary buffs, deal massive damage, or unleash special attacks against opponents. The plugin features full configuration support for balancing, permission nodes for admin control, and integration with standard Minecraft combat mechanics.
  1. Add the Sunrise Card item, identified by its custom model data and a persistent item tag.

  2. Implement two combat-only abilities with cooldowns and configurable damage, range, and effects.

  3. Register /sunrisecard give and provide the plugin metadata and default config.

Implemented the Sunrise Card plugin with:

  • A paper card marked with Custom Model Data 90001, plus a persistent tag to identify genuine cards.

  • Solar Burst on right-click and Dawn Nova on sneak + right-click. Both require recent combat and have configurable damage, range, effects, and cooldowns.

  • /sunrisecard give <player> for operators. Defaults are in config.yml.

Kodari can make mistakes. Review important code before using.
Files
src
Code
3 251
src/main/java/com/yerha/sunrisecard/SunriseCardPlugin.java
package com.yerha.sunrisecard;

import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XPotion;
import com.cryptomorin.xseries.XSound;
import com.cryptomorin.xseries.particles.XParticle;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public final class SunriseCardPlugin extends JavaPlugin implements Listener {
    private final Map<UUID, Long> lastCombatAt = new HashMap<>();
    private final Map<UUID, Long> burstCooldowns = new HashMap<>();
    private final Map<UUID, Long> novaCooldowns = new HashMap<>();
    private NamespacedKey cardKey;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        cardKey = new NamespacedKey(this, "sunrise_card");
        getServer().getPluginManager().registerEvents(this, this);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (args.length != 2 || !args[0].equalsIgnoreCase("give")) {
            sender.sendMessage(ChatColor.YELLOW + "Usage: /sunrisecard give <player>");
            return true;
        }
        if (!sender.hasPermission("sunrisecard.admin")) {
            sender.sendMessage(ChatColor.RED + "You do not have permission to give Sunrise Cards.");
            return true;
        }

        Player target = Bukkit.getPlayerExact(args[1]);
        if (target == null) {
            sender.sendMessage(ChatColor.RED + "That player is not online.");
            return true;
        }

        target.getInventory().addItem(createCard());
        sender.sendMessage(ChatColor.GOLD + "Gave a Sunrise Card to " + target.getName() + ".");
        target.sendMessage(ChatColor.GOLD + "You received the legendary Sunrise Card.");
        return true;
    }

    @EventHandler
    public void onCombatDamage(EntityDamageByEntityEvent event) {
        Player attacker = resolvePlayer(event.getDamager());
        if (attacker != null) {
            lastCombatAt.put(attacker.getUniqueId(), System.currentTimeMillis());
        }
        if (event.getEntity() instanceof Player victim) {
            lastCombatAt.put(victim.getUniqueId(), System.currentTimeMillis());
        }
    }

    @EventHandler
    public void onCardUse(PlayerInteractEvent event) {
        if (event.getHand() != EquipmentSlot.HAND || !isRightClick(event.getAction()) || !isCard(event.getItem())) {
            return;
        }

        event.setCancelled(true);
        Player player = event.getPlayer();
        if (!isInCombat(player)) {
            player.sendMessage(ChatColor.RED + "The Sunrise Card can only be used during combat.");
            return;
        }

        if (player.isSneaking()) {
            useDawnNova(player);
        } else {
            useSolarBurst(player);
        }
    }

    private void useSolarBurst(Player player) {
        if (!startCooldown(player, burstCooldowns, "abilities.solar-burst.cooldown-seconds")) {
            return;
        }

        double radius = getConfig().getDouble("abilities.solar-burst.radius", 5.0);
        double damage = getConfig().getDouble("abilities.solar-burst.damage", 8.0);
        int fireTicks = getConfig().getInt("abilities.solar-burst.fire-ticks", 60);
        Location center = player.getLocation();
        damageNearbyPlayers(player, center, radius, damage, fireTicks, false);
        XParticle.of("FLAME").ifPresent(particle -> player.getWorld().spawnParticle(particle.get(), center.clone().add(0, 1, 0), 45, 1.5, 0.8, 1.5, 0.04));
        XSound.matchXSound("ENTITY_BLAZE_SHOOT").ifPresent(sound -> sound.play(player));
        player.sendMessage(ChatColor.GOLD + "Solar Burst unleashed!");
    }

    private void useDawnNova(Player player) {
        if (!startCooldown(player, novaCooldowns, "abilities.dawn-nova.cooldown-seconds")) {
            return;
        }

        double radius = getConfig().getDouble("abilities.dawn-nova.radius", 7.0);
        double damage = getConfig().getDouble("abilities.dawn-nova.damage", 6.0);
        double knockback = getConfig().getDouble("abilities.dawn-nova.knockback", 1.35);
        Location center = player.getLocation();
        damageNearbyPlayers(player, center, radius, damage, 0, true, knockback);
        XParticle.of("FIREWORK").ifPresent(particle -> player.getWorld().spawnParticle(particle.get(), center.clone().add(0, 1, 0), 70, 2.0, 1.0, 2.0, 0.08));
        XSound.matchXSound("ENTITY_GENERIC_EXPLODE").ifPresent(sound -> sound.play(player));
        player.sendMessage(ChatColor.YELLOW + "Dawn Nova detonated!");
    }

    private void damageNearbyPlayers(Player source, Location center, double radius, double damage, int fireTicks, boolean applyBlindness) {
        damageNearbyPlayers(source, center, radius, damage, fireTicks, applyBlindness, 0.0);
    }

    private void damageNearbyPlayers(Player source, Location center, double radius, double damage, int fireTicks, boolean applyBlindness, double knockback) {
        double radiusSquared = radius * radius;
        for (Entity entity : source.getWorld().getNearbyEntities(center, radius, radius, radius)) {
            if (!(entity instanceof Player target) || target.equals(source) || target.isDead()
                    || target.getLocation().distanceSquared(center) > radiusSquared) {
                continue;
            }

            target.damage(damage, source);
            if (fireTicks > 0) {
                target.setFireTicks(Math.max(target.getFireTicks(), fireTicks));
            }
            if (applyBlindness) {
                XPotion.matchXPotion("BLINDNESS")
                        .map(potion -> potion.buildPotionEffect(40, 0))
                        .ifPresent(target::addPotionEffect);
            }
            if (knockback > 0) {
                Vector direction = target.getLocation().toVector().subtract(center.toVector()).setY(0.35);
                if (direction.lengthSquared() > 0) {
                    target.setVelocity(direction.normalize().multiply(knockback));
                }
            }
        }
    }

    private boolean startCooldown(Player player, Map<UUID, Long> cooldowns, String configPath) {
        long now = System.currentTimeMillis();
        long cooldownMillis = getConfig().getLong(configPath, 20L) * 1000L;
        long availableAt = cooldowns.getOrDefault(player.getUniqueId(), 0L);
        if (now < availableAt) {
            long secondsLeft = (long) Math.ceil((availableAt - now) / 1000.0);
            player.sendMessage(ChatColor.RED + "That ability is recharging for " + secondsLeft + "s.");
            return false;
        }
        cooldowns.put(player.getUniqueId(), now + cooldownMillis);
        return true;
    }

    private boolean isInCombat(Player player) {
        long lastHit = lastCombatAt.getOrDefault(player.getUniqueId(), 0L);
        long combatDuration = getConfig().getLong("combat-tag-seconds", 10L) * 1000L;
        return System.currentTimeMillis() - lastHit <= combatDuration;
    }

    private boolean isCard(ItemStack item) {
        if (item == null || item.getType().isAir() || !item.hasItemMeta()) {
            return false;
        }
        ItemMeta meta = item.getItemMeta();
        return meta != null && meta.hasCustomModelData()
                && meta.getCustomModelData() == getConfig().getInt("item.custom-model-data", 90001)
                && meta.getPersistentDataContainer().has(cardKey, PersistentDataType.BYTE);
    }

    private ItemStack createCard() {
        ItemStack item = XMaterial.matchXMaterial("PAPER").map(XMaterial::parseItem).orElse(null);
        if (item == null) {
            throw new IllegalStateException("Could not create the Sunrise Card item.");
        }
        ItemMeta meta = item.getItemMeta();
        if (meta == null) {
            throw new IllegalStateException("Could not configure the Sunrise Card item.");
        }
        meta.setDisplayName(ChatColor.GOLD + "" + ChatColor.BOLD + "Sunrise Card");
        meta.setLore(Arrays.asList(
                ChatColor.GRAY + "Right-click during combat: " + ChatColor.GOLD + "Solar Burst",