zbossgamerz
📎 1 file 1,550 chars
📄
pasted-code-1789485190169.txt
txt 21 lines
▶
Create a complete PaperMC plugin for Minecraft 1.21+ using Java 21 and the Paper API.

Plugin Name: EchoBlade
Features required:
1. Custom Item:
   - Netherite Sword named "&b&lEcho Blade" with custom lore and a unique PersistentDataContainer (PDC) key ("echo_blade").
   - Command `/echoblade give ` (permission `echoblade.admin`) to grant the item.

2. Core Mechanics:
   - On Melee Hit (EntityDamageByEntityEvent): When Player A hits Player B with the Echo Blade, record Player B's location, rotation, and current timestamp into a local tracking map. The tag expires after 5 seconds. Play a subtle particle effect (`PORTAL`) around Player B to signify they are tagged.
   - On Right-Click (PlayerInteractEvent): If Player A right-clicks with the Echo Blade and has an active tag on a target, instantly teleport that target back to the recorded location.
   - Retain Health/Damage: The target retains any damage taken between the initial hit and the teleport.
   - Cooldown: 15-second cooldown on the right-click rewind ability. Display remaining cooldown in the Action Bar.

3. Visuals & Audio:
   - Play sound `ENTITY_ENDERMAN_TELEPORT` at both source and destination locations upon rewind.
   - Spawn `REVERSE_PORTAL` particles along the vector between where the target was standing and where they were rewound to.

4. Code Structure:
   - Main class (`EchoBlade.java`), Event Listener class, and `paper-plugin.yml`.
   - Thread-safe tracking maps, clean PDC checks, and proper null-handling for disconnected players.
Kodari AI
KodariSep 15 at 3:16 pm 2
EchoBlade
A PaperMC plugin for Minecraft 1.21+ that adds a unique Netherite sword with time-rewind mechanics. Players can tag opponents on melee hits, storing their location and rotation for 5 seconds. Right-clicking the blade teleports the tagged target back to their recorded position, retaining all damage taken. Features a 15-second cooldown with action bar feedback, particle effects for tagging and teleportation, enderman teleport sounds, and reverse portal particles along the travel path. Includes admin command to grant the item with persistent data tracking.
  1. Create the Gradle project and Paper plugin metadata.

  2. Implement Echo Blade item creation, PDC validation, and /echoblade give.

  3. Implement tag tracking, rewind teleportation, cooldowns, particles, sounds, cleanup, and null-safe player handling.

Implemented EchoBlade from scratch:

  • Added Java 21 Gradle project with Paper 1.21 metadata.

  • Added EchoBlade item with custom name, lore, and PDC marker.

  • Added /echoblade give <player> with permission handling.

  • Added melee tagging with 5-second expiration and portal particles.

  • Added right-click rewind with:

    • Position and rotation restoration

    • Health preservation

    • 15-second cooldown

    • Action Bar cooldown display

    • Enderman teleport sounds

    • Reverse portal particle trail

  • Added thread-safe tracking maps and scheduled cleanup for expired tags and disconnected players.

zbossgamerz

tell me all the commands

Kodari AI
KodariSep 15 at 3:45 pm 1

The plugin currently has one command:

/echoblade give <player>

Gives the specified player an Echo Blade.

Permission: echoblade.admin

Examples:

Plain Text
/echoblade give Steve
/echoblade give Notch

The command can be run by players with the permission or from the console.

zbossgamerz

tell me how to use the weapon and all features of it

Kodari AI
KodariSep 15 at 3:46 pm 1

Echo Blade usage

1. Get the weapon

An administrator can give it to a player with:

Plain Text
/echoblade give <player>

Example:

Plain Text
/echoblade give Steve

Required permission:

Plain Text
echoblade.admin

The item is a Netherite Sword named:

Plain Text
&b&lEcho Blade

It is identified by a unique PDC key, so only the actual Echo Blade activates its abilities.


Rewind ability

Step 1: Hit a player

Use the Echo Blade to melee-hit another player.

When you hit them:

  • Their current location is recorded.

  • Their facing direction and pitch are recorded.

  • A timestamp is saved.

  • Portal particles appear around the target.

  • They become tagged for 5 seconds.

The tag is associated with the player you hit, so you can rewind that target after moving away.

Step 2: Right-click with the Echo Blade

While the target is still tagged, right-click using the Echo Blade.

The tagged player is immediately teleported back to:

  • The location where they were hit

  • Their original rotation and facing direction

The target keeps any health loss or damage received after the original hit. The rewind only changes their position and rotation; it does not restore their health.


Visual and audio effects

When the rewind activates:

  • ENTITY_ENDERMAN_TELEPORT plays at the target’s current location.

  • The same sound plays at the recorded destination.

  • REVERSE_PORTAL particles appear along the path between the two locations.

  • The target is transported instantly.

The initial hit also produces portal particles to indicate that the target has been tagged.


Tag expiration

Each hit creates or refreshes a tag for that target.

The tag expires after 5 seconds. If you wait too long, right-clicking will not rewind them, and you must hit them again.

Disconnected targets are safely removed from tracking.


Cooldown

After using the rewind ability, it has a 15-second cooldown.

During the cooldown:

  • The ability cannot be used.

  • The remaining cooldown is shown in the Action Bar.

  • Once the cooldown ends, you can tag a player again and use the rewind ability.

Basic example

Plain Text
1. Hit a player with the Echo Blade.
2. The target is tagged for 5 seconds.
3. The target runs away or takes damage.
4. Right-click with the Echo Blade.
5. The target returns to their original hit location with their current health unchanged.
6. Wait 15 seconds before using the ability again.
Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
5 340
src/main/java/com/kodari/echoblade/EchoBlade.java
package com.kodari.echoblade;

import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
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.NamespacedKey;

import java.util.Arrays;
import java.util.Map;

public final class EchoBlade extends JavaPlugin implements CommandExecutor {

    private NamespacedKey echoBladeKey;
    private Material echoBladeMaterial;
    private EchoBladeListener listener;

    @Override
    public void onEnable() {
        this.echoBladeKey = new NamespacedKey(this, "echo_blade");
        this.echoBladeMaterial = XMaterial.matchXMaterial("NETHERITE_SWORD")
                .map(XMaterial::parseMaterial)
                .orElseThrow(() -> new IllegalStateException("NETHERITE_SWORD is not available"));

        this.listener = new EchoBladeListener(this);
        Bukkit.getPluginManager().registerEvents(this.listener, this);
        this.listener.startCleanupTask();

        if (getCommand("echoblade") != null) {
            getCommand("echoblade").setExecutor(this);
        }
    }

    @Override
    public void onDisable() {
        if (this.listener != null) {
            this.listener.stopCleanupTask();
        }
    }

    ItemStack createEchoBlade() {
        ItemStack item = new ItemStack(this.echoBladeMaterial);
        ItemMeta meta = item.getItemMeta();
        if (meta == null) {
            throw new IllegalStateException("Unable to create Echo Blade metadata");
        }

        meta.setDisplayName(colorize("&b&lEcho Blade"));
        meta.setLore(Arrays.asList(
                colorize("&7A blade that echoes movement through time."),
                colorize("&8Hit a player, then right-click to rewind them."),
                colorize("&8The echo lasts for 5 seconds."),
                "",
                colorize("&b&lEcho Rewind")
        ));
        meta.getPersistentDataContainer().set(this.echoBladeKey, PersistentDataType.BYTE, (byte) 1);
        item.setItemMeta(meta);
        return item;
    }

    boolean isEchoBlade(ItemStack item) {
        if (item == null || item.getType() != this.echoBladeMaterial) {
            return false;
        }

        ItemMeta meta = item.getItemMeta();
        return meta != null
                && meta.getPersistentDataContainer().has(this.echoBladeKey, PersistentDataType.BYTE);
    }

    private String colorize(String text) {
        return ChatColor.translateAlternateColorCodes('&', text);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!sender.hasPermission("echoblade.admin")) {
            sender.sendMessage(colorize("&cYou do not have permission to use this command."));
            return true;
        }

        if (args.length != 2 || !args[0].equalsIgnoreCase("give")) {
            sender.sendMessage(colorize("&cUsage: /echoblade give <player>"));
            return true;
        }

        Player target = Bukkit.getPlayerExact(args[1]);
        if (target == null || !target.isOnline()) {
            sender.sendMessage(colorize("&cThat player is not online."));
            return true;
        }

        Map<Integer, ItemStack> leftovers = target.getInventory().addItem(createEchoBlade());
        leftovers.values().forEach(item -> target.getWorld().dropItemNaturally(target.getLocation(), item));
        sender.sendMessage(colorize("&aGave an &b&lEcho Blade &ato " + target.getName() + "."));
        if (!sender.equals(target)) {
            target.sendMessage(colorize("&aYou received a &b&lEcho Blade&a."));
        }
        return true;
    }
}