snipeyzen
📎 1 file 9,154 chars
📄
LightningRod_Plugin_Prompt.txt
txt 152 lines
▶
LIGHTNINGROD PLUGIN PROMPT
==========================
Platform: Paper 1.21.1
Java Version: Java 21
API Version: 1.21 (set in plugin.yml)


PROJECT SETUP
-------------

Plugin name: LightningRod
Main class path: com.yourpackage.LightningRodPlugin

Maven repository: PaperMC
Repository URL: https://repo.papermc.io/repository/maven-public/

Dependency:
  Group ID: io.papermc.paper
  Artifact ID: paper-api
  Version: 1.21.1-R0.1-SNAPSHOT
  Scope: provided

plugin.yml contents:
  name: LightningRod
  version: 1.0.0
  main: com.yourpackage.LightningRodPlugin
  api-version: 1.21
  commands:
    lightning:
      description: Give lightning rods to players
      usage: /lightning rod  
      permission: lightningrod.give
  permissions:
    lightningrod.give:
      default: op
    lightningrod.use:
      default: true


GENERAL MECHANICS
-----------------

TARGETING:
Use player.rayTraceBlocks() with a max distance of 100 blocks and FluidCollisionMode.NEVER. Extract the exact hit position using result.getHitPosition().toLocation() to get sub-block precision. This becomes the center point of the strike area. If the ray hits nothing (player looking at sky or beyond range), cancel silently with no message or action.

DAMAGE:
Every bolt must be spawned using world.strikeLightningEffect() which is visual and sound only and produces no vanilla damage, no fire spreading, and no mob AI triggers. After each bolt spawns, get all LivingEntity objects within a 2.5 block radius of the bolt location using world.getNearbyLivingEntities(location, 2.5). Call entity.damage(65.0) on each one. Exclude the player who cast the rod by checking entity.getUniqueId().equals(player.getUniqueId()) and skipping them.

Each bolt deals exactly 65 points of damage, which equals 32.5 hearts.

ROD DESTRUCTION:
The fishing rod must be destroyed immediately when the player right-clicks, before any lightning is scheduled. Set the item in the player's main hand to AIR using player.getInventory().setItemInMainHand(new ItemStack(Material.AIR)). This ensures the rod is consumed even if something goes wrong with the scheduled task afterward.

ROD IDENTIFICATION:
Both rod types are standard fishing rods (Material.FISHING_ROD) identified by a PersistentDataContainer key. The key namespace is the plugin instance and the key name is "lightningrod_type". The value is a STRING. Barrage rods store the value "barrage" and accurate rods store the value "accurate". On right-click, check for this key to confirm the item is a plugin rod before doing anything.


PERFORMANCE REQUIREMENTS (CRITICAL)
-------------------------------------

Never spawn all bolts in the same tick under any circumstances. Use BukkitRunnable scheduled with runTaskTimer to stagger bolt spawning across multiple ticks. Always use strikeLightningEffect() and never strikeLightning(). The strikeLightning() method triggers fire spreading, block ignition, mob AI reactions, and charged creeper conversions, all of which are expensive and must be avoided.

Spawn bolts in small batches per tick. Generate bolt coordinates on the fly inside the runnable using index math rather than pre-building large lists of Location objects.

Store active tasks in a Map keyed by player UUID (Map of UUID to BukkitTask). If a player triggers a rod while a task for them is already running, cancel the old task first before starting the new one. Call task.cancel() in the runnable's final iteration immediately after the last batch spawns to clean up the scheduler entry.


ROD TYPE 1: BARRAGE ROD
------------------------

Display name: (section symbol)c(lightning bolt symbol) Barrage Rod
Lore line 1: (section symbol)7Right-click to call a 40x40 lightning barrage
Lore line 2: (section symbol)7Travels East to West
Lore line 3: (section symbol)cSingle use

PersistentDataContainer key: lightningrod_type
PersistentDataContainer value: barrage

Grant command: /lightning rod barrage 

Strike area: 40 by 40 blocks centered on the raytrace hit location.

Wave direction: East to West. Bolts travel in columns of constant X value, starting from centerX + 20 and moving down to centerX - 20.

Bolt spacing: Every 2 blocks on both X and Z axes. This produces 20 columns each containing 20 bolts, for 400 total bolts.

Timing: Spawn one column per scheduler run. Use a period of 2 ticks between each column. Total animation duration is approximately 40 ticks (2 seconds).

Surface detection: For each bolt location, use world.getHighestBlockAt(x, z).getLocation().add(0, 1, 0) to place the bolt on top of the surface rather than underground or floating in the air. Be aware of Nether ceiling behavior and handle it appropriately using HeightMap.MOTION_BLOCKING_NO_LEAVES if needed.

Scheduler logic summary: Keep a column index counter starting at 0. Each tick, check if the column index has reached 20 and if so cancel the task and remove the player from the active tasks map. Otherwise calculate the X value for the current column, loop through all Z values in the area spaced 2 blocks apart, spawn a bolt at each location with strikeLightningEffect, apply damage to nearby entities, then increment the column index.


ROD TYPE 2: ACCURATE ROD
-------------------------

Display name: (section symbol)b(lightning bolt symbol) Accurate Rod
Lore line 1: (section symbol)7Right-click to call a 4x4 precision strike
Lore line 2: (section symbol)7Travels North to South
Lore line 3: (section symbol)cSingle use

PersistentDataContainer key: lightningrod_type
PersistentDataContainer value: accurate

Grant command: /lightning rod accurate 

Strike area: 4 by 4 blocks centered on the raytrace hit location.

Wave direction: North to South. Bolts travel in rows of constant Z value, starting from centerZ - 2 and moving to centerZ + 2.

Bolt spacing: Every 1 block on both X and Z axes. This produces 4 rows each containing 4 bolts, for 16 total bolts.

Timing: Spawn one row per scheduler run. Use a period of 1 tick between each row. Total animation duration is approximately 4 ticks (very fast and snappy).

Surface detection: Same as Barrage Rod, use getHighestBlockAt per bolt location.

Scheduler logic summary: Keep a row index counter starting at 0. Each tick, check if the row index has reached 4 and if so cancel the task and remove the player from the active tasks map. Otherwise calculate the Z value for the current row, loop through all X values in the area spaced 1 block apart, spawn a bolt at each location with strikeLightningEffect, apply damage to nearby entities, then increment the row index.


EVENT HANDLING
--------------

Listen to PlayerInteractEvent. Only proceed if the action is RIGHT_CLICK_AIR or RIGHT_CLICK_BLOCK. Check that the item in hand is not null and is Material.FISHING_ROD. Check that the item has item meta. Check that the PersistentDataContainer has the lightningrod_type key. Call event.setCancelled(true) to prevent the vanilla fishing cast animation.

After confirming the rod type, perform the raycast. If the result is null, return without doing anything. Otherwise get the center location from the hit position, destroy the rod immediately, cancel any existing active task for the player, then launch the appropriate barrage or accurate task.


COMMAND HANDLING
----------------

Register a CommandExecutor for the lightning command. Validate that the input matches exactly: /lightning rod  . If the format is wrong, send the sender a usage message. If the player name does not match an online player, send an error message saying the player is not found. If everything is valid, build the appropriate rod item and add it to the target player's inventory using targetPlayer.getInventory().addItem(). Send the command sender a confirmation message such as "Given Barrage Rod to " and optionally notify the receiving player as well.


HELPER METHOD: damageEntitiesAt
---------------------------------

This method takes a Location and the casting Player as parameters. It calls world.getNearbyLivingEntities(location, 2.5) to get all living entities within 2.5 blocks. It loops through each entity, skips any whose UUID matches the casting player's UUID, and calls entity.damage(65.0) on the rest.


ADDITIONAL NOTES FOR THE DEVELOPER
------------------------------------

Test getHighestBlockAt behavior in the Nether since the bedrock ceiling causes it to return the ceiling instead of the floor. Consider using world.getHighestBlockYAt(x, z, HeightMap.MOTION_BLOCKING_NO_LEAVES) as a safer alternative across all dimension types.

The plugin should use Paper-specific imports where available rather than falling back to legacy Bukkit-only APIs.

Do not use deprecated methods from older Bukkit API versions. Target Paper 1.21.1 APIs throughout.

The rod item should not be enchantable or stackable in ways that bypass the single-use behavior. Consider setting the max stack size to 1 if the API supports it, or handle the case where a player has multiple rods in one slot.

No configuration file is required for this plugin. All values are hardcoded as described in this prompt.
Kodari AI
KodariMay 22 at 3:28 pm 12,191 (v2)

I’ll create a Lightning Rod plugin for Paper 1.21.1 that spawns visual lightning strikes with custom damage mechanics.

LightningRod
A Paper 1.21.1 plugin that adds consumable lightning rod items for calling devastating lightning strikes. Features two rod types: Barrage Rod (40x40 area, 400 bolts traveling east-to-west) and Accurate Rod (4x4 precision strike, 16 bolts north-to-south). Uses raytracing for precise targeting, visual-only lightning effects, and custom damage mechanics dealing 65 damage per bolt to entities within 2.5 blocks.

LightningRod plugin created!

The plugin features:

  • Barrage Rod: 40×40 area with 400 lightning bolts traveling east-to-west in columns (2-tick intervals)

  • Accurate Rod: 4×4 precision strike with 16 bolts traveling north-to-south in rows (1-tick intervals)

  • Raytracing for precise targeting up to 100 blocks

  • Visual-only lightning effects with custom damage (65 damage per bolt = 32.5 hearts)

  • Single-use consumable rods with PersistentDataContainer identification

  • Task tracking to prevent overlapping casts

  • Caster immunity (players won’t damage themselves)

Use /lightning rod barrage <player> or /lightning rod accurate <player> to grant rods. Right-click with the rod to unleash devastating lightning strikes at your crosshair location!

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
7 386
src/main/java/com/example/lightningrod/LightningRodPlugin.java
package com.example.lightningrod;

import com.example.lightningrod.command.LightningCommand;
import com.example.lightningrod.listener.RodListener;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;

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

public class LightningRodPlugin extends JavaPlugin {
    
    private NamespacedKey rodTypeKey;
    private final Map<UUID, BukkitTask> activeTasks = new HashMap<>();
    
    @Override
    public void onEnable() {
        this.rodTypeKey = new NamespacedKey(this, "lightningrod_type");
        
        getCommand("lightning").setExecutor(new LightningCommand(this));
        Bukkit.getPluginManager().registerEvents(new RodListener(this), this);
        
        getLogger().info("LightningRod plugin enabled!");
    }
    
    @Override
    public void onDisable() {
        activeTasks.values().forEach(BukkitTask::cancel);
        activeTasks.clear();
        
        getLogger().info("LightningRod plugin disabled!");
    }
    
    public NamespacedKey getRodTypeKey() {
        return rodTypeKey;
    }
    
    public Map<UUID, BukkitTask> getActiveTasks() {
        return activeTasks;
    }
}