Ty Wilson
πŸ“Ž 1 file 6,183 chars
πŸ“„
pasted-code-1788150087264.txt
txt 214 lines
β–Ά
# Paper 1.21.11 Custom Weapon β€” Speed Sword

Create a custom weapon for a Minecraft SMP running **Paper 1.21.11**.

Use the **modern Paper 1.21.11 API** and avoid deprecated or outdated Bukkit/Spigot approaches whenever possible.

## Weapon: Speed Sword

The weapon is called **Speed Sword**.

### Base Item

* Base material: `NETHERITE_SWORD`
* Enchantment: `SHARPNESS II`
* Display name: **Speed Sword**
* The sword must have a unique internal identifier so it cannot be confused with a normal Netherite Sword.

Use the item's **PersistentDataContainer (PDC)** to identify the weapon rather than checking its display name.

## Special Ability β€” Speed I

The Speed Sword gives its wielder **Speed I** while the sword is actively held in their main hand.

### Behavior

When a player switches to the Speed Sword:

* Give the player `SPEED` level 1.
* The effect should remain active while the Speed Sword is held in the main hand.

When the player switches away from the Speed Sword:

* Remove the Speed effect that was provided by the Speed Sword.

The implementation must prevent the Speed effect from stacking or constantly refreshing unnecessarily.

### Important Potion Effect Behavior

Do **not** accidentally remove a Speed effect that came from another source.

For example, if a player already has Speed from a potion, beacon, command, or another custom item, switching away from the Speed Sword should not blindly remove that unrelated Speed effect.

The plugin should distinguish between Speed provided by the Speed Sword and Speed provided by other sources as much as reasonably possible with the Paper API.

The Speed Sword should also work correctly when:

* The player joins the server.
* The player respawns.
* The player dies.
* The player changes hotbar slots.
* The player drops the sword.
* The player picks the sword back up.
* The sword is moved between inventory slots.
* The player disconnects and reconnects.

## Crafting Recipe

Create a custom shaped crafting recipe for the Speed Sword.

### Required Materials

* 1Γ— Diamond Sword
* 2Γ— Netherite Scrap
* 4Γ— Diamond Block
* 2Γ— Sugar Cane

### Exact 3Γ—3 Recipe

```text
[Diamond Block] [Sugar Cane]    [Diamond Block]
[Netherite Scrap] [Diamond Sword] [Netherite Scrap]
[Diamond Block] [Sugar Cane]    [Diamond Block]
```

The crafting table should produce exactly **1 Speed Sword**.

The recipe must not accept incorrect materials or incorrect item positions.

## Custom Item Identification

Use a `NamespacedKey` and the item's `PersistentDataContainer`.

For example, create a custom PDC value similar to:

`speed_sword`

The exact implementation is up to you, but the plugin must reliably determine whether an ItemStack is the custom Speed Sword.

Do NOT rely solely on:

* Display name
* Lore
* Enchantments
* Material type

A normal Netherite Sword with Sharpness II should NOT be treated as a Speed Sword.

## Item Persistence

The Speed Sword must retain its custom identifier when:

* Dropped on the ground
* Picked up
* Stored in a chest
* Stored in a shulker box
* Moved through inventories
* Logged out with it
* Logged back in with it

## Item Appearance

Give the sword a clearly visible custom name:

**Speed Sword**

Optionally add lore describing its ability, such as:

**Ability:**
`While held: Speed I`

Do not make the lore responsible for identifying the sword.

## Architecture

Organize the plugin cleanly.

Recommended structure:

```text
src/main/java/
└── your/package/name/
    β”œβ”€β”€ Main.java
    β”œβ”€β”€ SpeedSword.java
    β”œβ”€β”€ SpeedSwordListener.java
    └── SpeedSwordRecipe.java
```

You may change the structure if there is a cleaner implementation.

### Main Class

The main plugin class should:

* Extend `JavaPlugin`
* Register the Speed Sword recipe
* Register the required event listeners
* Initialize the Speed Sword system

### SpeedSword Class

Create reusable methods for:

* Creating the Speed Sword
* Checking whether an ItemStack is the Speed Sword
* Applying the sword's ability
* Removing the sword's ability
* Getting the custom PDC identifier

### Listener

Create the necessary listeners for detecting when the player starts or stops holding the sword.

Use appropriate Paper/Bukkit events rather than constantly running expensive checks on every player.

If a repeating task is necessary, make it efficient and explain why it is being used.

## Edge Cases

Make sure the plugin handles these situations correctly:

1. Player switches from Speed Sword β†’ normal item.
2. Player switches from normal item β†’ Speed Sword.
3. Player dies while holding the sword.
4. Player respawns while the sword is in their inventory.
5. Player disconnects while holding the sword.
6. Player reconnects with the sword.
7. Player drops the sword.
8. Player picks the sword back up.
9. Player moves the sword between inventory slots.
10. Player already has Speed from another source.
11. Player has multiple Speed Swords in their inventory.
12. A normal Netherite Sword with Sharpness II is not treated as the custom weapon.

## Code Requirements

Write complete, production-ready Java code for **Paper 1.21.11**.

Do not use obsolete APIs simply because they work on older Minecraft versions.

Include:

* All Java classes
* All imports
* `plugin.yml`
* `pom.xml` or Gradle configuration appropriate for Paper 1.21.11
* Correct Paper API dependency
* Correct Java version required by Paper 1.21.11
* Instructions for compiling and installing the plugin

Make sure the code is internally consistent and compiles without missing classes, imports, methods, or dependencies.

## Final Goal

The finished plugin should add exactly one custom SMP weapon:

**βš” Speed Sword**

**Material:** Netherite Sword
**Enchantment:** Sharpness II
**Ability:** Speed I while held in the main hand
**Crafting:** 4 Diamond Blocks + 2 Sugar Cane + 2 Netherite Scrap + 1 Diamond Sword

The weapon should feel like a polished custom SMP item rather than simply being a renamed Netherite Sword.
Kodari AI
KodariAug 31 at 4:29 am 2
SpeedSwordPlugin
A Paper 1.21.11 plugin that adds a custom Speed Sword item. The sword is a Netherite Sword with Sharpness II that grants Speed I while held in the main hand. Uses PersistentDataContainer for reliable item identification, tracks the source of the Speed effect to avoid removing unrelated effects, handles all edge cases (death, respawn, disconnect, inventory movement), and includes a custom shaped crafting recipe requiring Diamond Blocks, Sugar Cane, Netherite Scrap, and a Diamond Sword.
  1. Create the Gradle/Paper 1.21.11 project configuration and plugin metadata.

  2. Implement the PDC-identified Speed Sword item and ability lifecycle.

  3. Add exact shaped crafting and event listeners for inventory, lifecycle, and effect edge cases.

Implemented the Paper 1.21.11 Speed Sword plugin.

Included:

  • Gradle build configured for Java 21 and Paper 1.21.11

  • plugin.yml

  • PDC-based speed_sword identification

  • Netherite Sword with Sharpness II

  • Custom Adventure display name and lore

  • Speed I while held in the main hand

  • Protection against removing unrelated Speed effects

  • Handling for joins, respawns, deaths, quits, hotbar changes, drops, pickups, inventory moves, item breaks, world changes, and off-hand swaps

  • Exact shaped crafting recipe:

    Plain Text
    D C D
    N W N
    D C D
    

    Where:

    • D = Diamond Block

    • C = Sugar Cane

    • N = Netherite Scrap

    • W = Diamond Sword

Build and install:

Shell
./gradlew build

Copy the resulting JAR from:

Plain Text
build/libs/speed-sword-1.0.0.jar

to the server’s plugins/ directory, then restart the Paper server.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
7 367
src/main/java/com/kodari/speedsword/SpeedSwordPlugin.java
package com.kodari.speedsword;

import org.bukkit.plugin.java.JavaPlugin;

public final class SpeedSwordPlugin extends JavaPlugin {
    private SpeedSword speedSword;

    @Override
    public void onEnable() {
        this.speedSword = new SpeedSword(this);
        new SpeedSwordRecipe(this, this.speedSword).register();
        getServer().getPluginManager().registerEvents(new SpeedSwordListener(this, this.speedSword), this);
    }

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