Anton pesonen

make me an orbital strike cannon plugin whi stasis rod, nuke rod and stab rod

Kodari AI
KodariOct 3 at 7:50 am 1
OrbitalStrikeRods
OrbitalStrikeRods is a Minecraft plugin that adds three powerful rod items to the game. The Stasis Rod freezes targeted entities in place with a time-lock effect. The Nuke Rod summons a devastating orbital bombardment that deals massive area damage with explosion effects and screen shake. The Stab Rod performs a rapid melee-style strike with high damage and knockback. Each rod has a custom crafting recipe, cooldown system, particle effects, and sound effects. Players can obtain rods through crafting or commands, with configurable damage values, cooldown durations, and permission nodes. The plugin includes a command system for giving rods to players and reloading configuration files.
  1. Add the Paper plugin setup and /orbitalstrike give command.

  2. Implement custom Stasis, Nuke, and Stab rods with targeting, effects, and cooldowns.

  3. Register the command and interaction handlers in plugin.yml.

Created the OrbitalStrike plugin with /osc give <player> <stasis|nuke|stab>.

  • Stasis Rod: immobilizes a targeted living entity for 5 seconds.

  • Nuke Rod: calls down a delayed strike that damages entities but does not damage blocks.

  • Stab Rod: deals 12 damage to a targeted living entity.

The give command requires the orbitalstrike.admin permission, which defaults to operators.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
4 304
src/main/java/com/kodari/orbitalstrike/OrbitalStrikePlugin.java
package com.kodari.orbitalstrike;

import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XPotion;
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.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
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.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEntityEvent;
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.List;
import java.util.Map;
import java.util.UUID;

public final class OrbitalStrikePlugin extends JavaPlugin implements Listener, CommandExecutor {
    private static final String PREFIX = ChatColor.DARK_GRAY + "[" + ChatColor.AQUA + "OrbitalStrike" + ChatColor.DARK_GRAY + "] ";
    private final Map<String, Long> cooldowns = new HashMap<>();
    private NamespacedKey rodKey;

    @Override
    public void onEnable() {
        rodKey = new NamespacedKey(this, "rod_type");
        Bukkit.getPluginManager().registerEvents(this, this);
        if (getCommand("orbitalstrike") != null) {
            getCommand("orbitalstrike").setExecutor(this);
        }
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (args.length != 3 || !args[0].equalsIgnoreCase("give")) {
            sender.sendMessage(PREFIX + ChatColor.YELLOW + "Usage: /orbitalstrike give <player> <stasis|nuke|stab>");
            return true;
        }

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

        RodType type = RodType.fromId(args[2]);
        if (type == null) {
            sender.sendMessage(PREFIX + ChatColor.RED + "Choose stasis, nuke, or stab.");
            return true;
        }

        ItemStack rod = createRod(type);
        if (rod == null) {
            sender.sendMessage(PREFIX + ChatColor.RED + "Could not create that rod.");
            return true;
        }
        target.getInventory().addItem(rod).values().forEach(item -> target.getWorld().dropItemNaturally(target.getLocation(), item));
        sender.sendMessage(PREFIX + ChatColor.GREEN + "Gave " + type.displayName + ChatColor.GREEN + " to " + target.getName() + ".");
        return true;
    }

    @EventHandler(ignoreCancelled = true)
    public void onPlayerInteract(PlayerInteractEvent event) {
        if (event.getHand() != EquipmentSlot.HAND || !event.getAction().isRightClick()) {
            return;
        }
        if (useRod(event.getPlayer(), event.getItem())) {
            event.setCancelled(true);
        }
    }

    @EventHandler(ignoreCancelled = true)
    public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
        if (event.getHand() != EquipmentSlot.HAND) {
            return;
        }
        if (useRod(event.getPlayer(), event.getPlayer().getInventory().getItemInMainHand())) {
            event.setCancelled(true);
        }
    }

    private boolean useRod(Player player, ItemStack item) {
        RodType type = getRodType(item);
        if (type == null) {
            return false;
        }

        switch (type) {
            case STASIS -> useStasisRod(player);
            case NUKE -> useNukeRod(player);
            case STAB -> useStabRod(player);
        }
        return true;
    }

    private void useStasisRod(Player player) {
        Entity target = player.getTargetEntity(24);
        if (!(target instanceof LivingEntity livingTarget)) {
            player.sendMessage(PREFIX + ChatColor.RED + "Aim at a living target within 24 blocks.");
            return;
        }
        if (!tryUse(player, RodType.STASIS)) {
            return;
        }

        if (livingTarget instanceof Player targetPlayer) {
            XPotion.matchXPotion("SLOWNESS").map(potion -> potion.buildPotionEffect(100, 10))
                    .ifPresent(effect -> targetPlayer.addPotionEffect(effect, true));
            XPotion.matchXPotion("JUMP_BOOST").map(potion -> potion.buildPotionEffect(100, 128))
                    .ifPresent(effect -> targetPlayer.addPotionEffect(effect, true));
        } else {
            boolean hadAi = livingTarget.hasAI();
            livingTarget.setAI(false);
            Bukkit.getScheduler().runTaskLater(this, () -> {
                if (livingTarget.isValid()) {
                    livingTarget.setAI(hadAi);
                }
            }, 100L);
        }

        player.sendMessage(PREFIX + ChatColor.AQUA + livingTarget.getName() + " has been locked in stasis for 5 seconds.");
        XParticle.of("END_ROD").ifPresent(particle -> livingTarget.getWorld().spawnParticle(particle.get(), livingTarget.getLocation().add(0, 1, 0), 25, 0.5, 0.8, 0.5, 0.02));
    }

    private void useNukeRod(Player player) {
        if (!tryUse(player, RodType.NUKE)) {
            return;
        }

        Block targetBlock = player.getTargetBlockExact(100);
        Location target;
        if (targetBlock != null) {
            target = targetBlock.getLocation().add(0.5, 1, 0.5);
        } else {
            Vector direction = player.getEyeLocation().getDirection().normalize().multiply(30);
            target = player.getEyeLocation().add(direction);
        }
        Location strikeLocation = target.clone();
        player.sendMessage(PREFIX + ChatColor.RED + "Orbital strike locked. Impact in 3 seconds!");

        Bukkit.getScheduler().runTaskLater(this, () -> {
            if (!player.isOnline()) {
                return;
            }
            XParticle.of("END_ROD").ifPresent(particle -> {
                for (int height = 4; height <= 40; height += 4) {
                    Location beamPoint = strikeLocation.clone().add(0, height, 0);
                    strikeLocation.getWorld().spawnParticle(particle.get(), beamPoint, 12, 0.25, 1.5, 0.25, 0.03);
                }
            });
            strikeLocation.getWorld().createExplosion(strikeLocation, 8.0F, false, false);
            player.sendMessage(PREFIX + ChatColor.DARK_RED + "Orbital strike impact!");
        }, 60L);
    }

    private void useStabRod(Player player) {
        Entity target = player.getTargetEntity(5);
        if (!(target instanceof LivingEntity livingTarget)) {
            player.sendMessage(PREFIX + ChatColor.RED + "Aim at a living target within 5 blocks.");
            return;
        }
        if (!tryUse(player, RodType.STAB)) {
            return;
        }

        livingTarget.damage(12.0, player);
        player.sendMessage(PREFIX + ChatColor.RED + "You stabbed " + livingTarget.getName() + ".");
    }

    private boolean tryUse(Player player, RodType type) {
        String key = player.getUniqueId() + ":" + type.id;
        long now = System.currentTimeMillis();
        long readyAt = cooldowns.getOrDefault(key, 0L);
        if (now < readyAt) {
            long seconds = Math.max(1, (readyAt - now + 999) / 1000);
            player.sendMessage(PREFIX + ChatColor.YELLOW + "Wait " + seconds + "s before using this rod again.");
            return false;
        }
        cooldowns.put(key, now + type.cooldownMillis);
        return true;
    }

    private ItemStack createRod(RodType type) {
        ItemStack item = XMaterial.matchXMaterial("BLAZE_ROD").map(XMaterial::parseItem).orElse(null);