📄
pasted-code-1788600760714.txt
txt
211 lines
▶
# MAIN PROMPT: Build the "KnifeSwap" Minecraft Plugin
You are an expert Minecraft plugin developer (Java, Spigot/Paper API). Build a complete, working, production-quality plugin called **KnifeSwap**, targeting **Minecraft version 1.21.11**. Use the Spigot/Paper API version corresponding to 1.21.11, ensure `plugin.yml` declares `api-version: 1.21`, and make sure all APIs used (items, sounds, particles, events, scheduler) are valid and non-deprecated for this version. Read this entire prompt before writing any code. Follow every requirement exactly. Do not skip, simplify, or reinterpret any rule. Do not add any feature, system, or mechanic that is not explicitly described below.
## 1. What This Plugin Is
KnifeSwap is a minigame plugin. A group of participants is chosen. One participant at a time holds a special "Knife" item. The Knife holder can eliminate other participants by killing them. When a kill happens, the Knife passes to the next eligible participant for a new round. This continues until only one participant remains — that participant is the winner.
The single most important rule in this entire plugin: **the Knife must always be a real, physical Minecraft inventory item that the holder can see, hold, and use.** The plugin must never simulate "having the Knife" through only internal variables/state/timers while the player's inventory does not actually contain the item. Every single time the Knife changes hands, the physical item must be removed from the old holder and given to the new holder, in sync with the internal game state, with zero exceptions.
## 2. Commands
### `/knifeswap start [player...]`
- Example: `/knifeswap start Aditya_ggs shloktyagi`
- All listed players become participants.
- Requires at least 2 valid participants, or the command must fail with a clear error message and not start a game.
- If a KnifeSwap game is already running, this command must fail with a clear error message and must not affect the running game.
- On success, this triggers the countdown (Section 4), and gameplay begins only after the countdown finishes.
### `/knifeswap stop`
- Immediately stops the current game, whatever state it is in.
- Removes the Knife item from whichever player is holding it.
- Cancels every active timer/scheduled task related to the game.
- Clears all internal game state completely.
- After this command, `/knifeswap start ...` must be able to start a brand-new game with no leftover state, items, sounds, or effects from the previous game.
- If no game is running, fail gracefully with a clear message.
### Tab Completion
- Typing `/knifeswap ` suggests: `start`, `stop`.
- Typing `/knifeswap start ` suggests currently online player names.
- Typing `/knifeswap start A` suggests only online player names matching the partial input `A` (case-insensitive prefix match).
- Support suggesting multiple additional player names after the first, since the command accepts multiple players.
## 3. Countdown Sequence
When `/knifeswap start` succeeds, before any gameplay begins:
1. Show a large screen title `3` to all participants, with an appropriate countdown sound.
2. Wait roughly 1 second, then show `2` with an appropriate countdown sound.
3. Wait roughly 1 second, then show `1` with an appropriate countdown sound.
4. Wait roughly 1 second, then show `GO!` with:
- A stronger/more exciting sound effect than the numbers used (distinct from the `3`/`2`/`1` sound).
- A small, lightweight particle effect (visible but not excessive).
5. Only after `GO!` is displayed does actual gameplay begin (Knife selection, attacks, eliminations, etc.). Nothing gameplay-related should be active or possible during the countdown itself (e.g., no eliminations or Knife handling before `GO!`).
Use Bukkit/Paper's scheduler for all timing — do not use blocking sleeps.
## 4. The Knife Item
Create a custom item representing the Knife:
- Display name: `Knife`.
- Base item: a **completely standard, vanilla Netherite Sword** — do not add custom enchantments, attack damage/speed modifiers, attributes, lore, unbreakable flags, or any other modification to the item. The only visible change from a normal Netherite Sword is that its display name is set to `Knife`. It should behave exactly like a regular Netherite Sword in combat (same damage, same attack speed, same durability behavior).
- The item must carry a **reliable, unique internal identifier** (e.g., a persistent data container tag, NamespacedKey, or equivalent mechanism) so the plugin can always programmatically confirm "this exact item is the KnifeSwap Knife," independent of its display name. Never identify the Knife by display name alone, since a player could theoretically obtain or rename an unrelated Netherite Sword to also say `Knife`. This identifier tag should be the only non-vanilla addition to the item — it must not otherwise alter the item's appearance or stats.
- The Knife must be a genuine item sitting in the player's inventory/hotbar — fully visible in their hotbar, fully holdable, and usable to attack other players like a normal weapon.
## 5. Giving/Receiving the Knife (Initial Selection After `GO!`)
Immediately after `GO!`:
1. Select one participant to receive the Knife, according to your own reasonable, clearly-documented selection logic (e.g., random selection among all active participants) since a specific algorithm was not mandated — just make it deterministic-enough to be fair and make the logic clear in code comments.
2. Physically add the Knife item to that player's inventory. Verify it is actually present — do not just mark internal state.
3. Play a suitable "received the Knife" sound to that player (and optionally nearby/all participants).
4. Spawn a small, lightweight particle effect around the new holder.
5. Optionally show a short title or action-bar message to that player indicating they now hold the Knife (e.g., "You have the Knife!").
6. Update internal state: mark this player as the current Knife holder.
Keep all feedback (sounds/particles/messages) tasteful and non-excessive — this is feedback, not the actual game logic.
## 6. Core Gameplay Loop
- The current Knife holder is the only participant capable of eliminating others via the Knife for the purposes of this game's win condition. Detect when the Knife holder deals a killing blow to another active participant (e.g., via the death event, checking that the damager was holding the Knife item and the victim was an active, non-eliminated participant).
- On a valid elimination:
1. Correctly detect the elimination (do not rely on guesswork — check the actual combat/death event and confirm the killer was holding the Knife and the victim was an active participant).
2. Play an appropriate kill/elimination sound.
3. Spawn an appropriate elimination particle effect (short burst, not excessive).
4. Update game state: mark the victim as eliminated (no longer active).
5. Proceed to Section 7 (new round / Knife swap) unless the win condition (Section 8) is now met.
The plugin must, at all times, correctly track:
- The full list of active (still-in-game, non-eliminated) participants.
- The full list of eliminated participants.
- Who the current Knife holder is (if anyone).
- The current round number.
- The overall game state (e.g., not-running / countdown / in-progress / ended).
- The winner, once determined.
## 7. New Rounds / Knife Swapping
Whenever the game advances to a new round (i.e., after a valid elimination, and the game has not yet been won):
1. Remove the Knife from the previous holder physically (from their inventory) — do not leave a duplicate or leftover Knife item anywhere.
2. Reset the previous holder's "is Knife holder" state internally.
3. Select the next eligible active participant to receive the Knife, using your documented selection logic (e.g., random among remaining active participants, excluding the player who just got eliminated). Document this logic clearly in code comments.
4. Physically give the new Knife item to that player's inventory. Confirm it is actually present.
5. Confirm the previous holder no longer has an active/functional Knife.
6. Play a suitable Knife-transfer/receive sound.
7. Spawn a small particle effect around the new holder.
8. Increment/update the round counter.
9. Resume normal gameplay.
This exact sequence must work correctly and reliably for every single round of the game, not only the first transfer. Write this as reusable logic (e.g., a single "give Knife to player X" method that is called both for the initial selection and every subsequent round) rather than duplicating logic — this reduces the risk of the physical item and internal state ever going out of sync.
## 8. Eliminated Participants
Once a participant is eliminated:
- They are immediately removed from the active participant list and added to the eliminated list.
- They must never be selected as a future Knife holder.
- They must not interfere with ongoing gameplay (e.g., ignore them for elimination checks, Knife selection, and win-condition checks going forward).
- Their elimination must be properly and persistently stored in the plugin's in-memory game state for the remainder of the game (used for e.g. announcing results, debugging, or future logic).
- Play a short, non-excessive elimination sound/particle burst at the moment of elimination (as described in Section 6) — do not create prolonged or looping effects.
## 9. Winner / Game End
The game continues until exactly one eligible active participant remains.
When that happens:
1. Declare that remaining participant the winner.
2. Prominently display the winner's name to the players (e.g., a title/broadcast such as " wins!").
3. Play a suitable victory sound.
4. Create a celebratory particle effect around the winner (rewarding but lightweight — must not cause lag; do not use large or continuously-looping particle effects).
5. Remove the Knife from play entirely (from the winner's inventory or wherever it currently is).
6. Stop the game.
7. Cancel every active timer/scheduled task tied to the game.
8. Clear all internal game state completely.
9. After this, a brand-new `/knifeswap start ...` must work normally with no leftovers.
## 10. Players Leaving Mid-Game
If any participant disconnects/leaves the server while a game is in progress:
- Handle this safely without throwing errors or leaving the plugin in a broken state.
- Remove or appropriately update that player from the active participant list (treat them as no longer eligible to continue).
- If the leaving player was the current Knife holder, safely recover: proceed as if they were just eliminated for the purpose of Knife-swapping (select a new eligible participant and follow the full Knife-swap procedure in Section 7), even though this was not a "kill" — just a departure. Do not let the game get stuck waiting on a player who is gone.
- After removing the leaving player, immediately check the win condition again: if only one eligible active participant now remains, declare them the winner and follow the full winner procedure in Section 9.
- Never leave the game in a state where it is running but has no valid Knife holder and more than one active participant remaining — always recover automatically.
## 11. Sounds — General Rules
Use clear, appropriate built-in Minecraft sounds (via the Bukkit/Paper `Sound` enum) for:
- Each countdown number (`3`, `2`, `1`)
- `GO!` (a distinctly stronger/more exciting sound than the countdown numbers)
- Receiving the Knife (initial and every subsequent transfer)
- Successful elimination/kill
- Player elimination
- Winner announcement
- Game start and game end
Rules for all sounds:
- Play each sound only at the specific moment it is relevant — never spam or repeat unnecessarily.
- Use sensible volume and pitch values so they feel like natural, polished Minecraft feedback rather than jarring or intrusive noise.
- Do not add sounds anywhere that was not explicitly requested above.
## 12. Particles — General Rules
Use lightweight, visually clear Bukkit/Paper particle effects for:
- `GO!`
- Knife received (initial and every subsequent transfer)
- Elimination
- Winner announcement
Rules for all particles:
- Keep effects small in scale and short in duration (a brief burst, not a sustained emitter).
- Never create a permanent/looping particle effect unless there is no reasonable alternative — and if you must, it should be trivially cheap performance-wise and clearly justified in a code comment.
- Prioritize performance — the plugin should never cause noticeable lag from particles, even with many participants.
- Sounds and particles are purely feedback layered on top of the real game logic described in Sections 5–10. They must never be used as a substitute for, or stand-in for, actual state changes (e.g., never "give a particle effect that looks like the player has the Knife" without also giving them the real item and updating real state).
## 13. Clean Restart Guarantee
After `/knifeswap stop` is used, or after a game ends naturally with a winner, the plugin must guarantee:
- No previous participants remain "stuck" in any game-related state.
- No leftover Knife item exists anywhere (inventories, ground, etc. that the plugin is responsible for).
- No leftover sounds, particle tasks, or scheduled tasks continue running.
- All internal state (active list, eliminated list, holder, round, game state, winner) is fully reset.
- A new `/knifeswap start [player...]` immediately afterward must behave exactly like starting the very first game ever, with no residual effects from prior games.
## 14. Explicit Scope Limits — Do Not Add These
Do not implement or include any of the following, even if they seem like natural extensions:
- Economy systems
- Shops
- Kits
- Coins/currency
- Teams
- Leveling/XP systems
- Cosmetics
- GUI menus
- Additional/alternate game modes
- Any other gameplay system not explicitly described above
Keep the plugin strictly focused on exactly the KnifeSwap gameplay described in this prompt. Do not invent extra mechanics, rules, items, commands, or configuration options beyond what is specified here.
## 15. Engineering Expectations
- Use a clean, organized code structure (e.g., separate classes for the game manager/state, the command/tab-completion handler, the Knife item factory/identifier logic, and event listeners for combat/death/quit events).
- Centralize the "give Knife to player" logic into one reusable method used by both the initial selection and every subsequent round, so the physical item and internal state can never drift out of sync.
- Centralize the "remove Knife from player" logic similarly.
- Use the Bukkit/Paper scheduler (not `Thread.sleep`) for all delays (countdown, effect timing, etc.).
- Handle edge cases defensively: invalid/missing player names in `/knifeswap start`, attempting to start with fewer than 2 valid participants, attempting to start while a game is already running, attempting to stop with no game running, a player disconnecting at any point in the game (including during the countdown), and any other reasonably foreseeable edge case implied by the rules above.
- Write clear code comments, especially anywhere you had to make a reasonable implementation choice because the exact mechanism wasn't specified (e.g., the random-selection algorithm for choosing the next Knife holder).
- Produce a complete, compilable Spigot/Paper plugin (plugin.yml, main class, all necessary supporting classes) — not a partial sketch.
- Target Minecraft **1.21.11** specifically: use the matching Spigot/Paper API dependency version in the build file (e.g., Maven/Gradle), and set `api-version: 1.21` in `plugin.yml`.
## 16. Final Reminder
The single non-negotiable requirement across this entire plugin: **whenever the plugin's internal state says a player "has the Knife," that player's actual Minecraft inventory must physically contain the Knife item at that exact moment — with zero exceptions, for the very first Knife and for every single subsequent round.** Sounds and particles are cosmetic feedback only and must never replace this real, physical item transfer and matching state update.
Build KnifeSwap now, exactly as specified above.
Create the Gradle project and plugin manifest for Paper 1.21.11.
Add the physical Knife item factory with a persistent identifier.
Add the game manager covering countdowns, rounds, transfers, eliminations, quits, winners, and cleanup.
Add command/tab completion and event listeners for gameplay protection and combat handling.
Created the complete KnifeSwap plugin project with:
Paper 1.21.11 Gradle setup and
plugin.ymlPhysical tagged Netherite Sword Knife item
Countdown sequence with sounds, titles, and particles
Random Knife assignment and round transfers
Valid Knife-kill detection and eliminations
Winner handling and full cleanup
Quit/death recovery logic
Knife drop, inventory movement, and countdown combat protection
/knifeswap start <player> [player...]/knifeswap stopCase-insensitive tab completion for commands and online players
player is not getting the netherite sword and the game is not ending when remaining player are kill and we cannot enter more than two player name so fix it
Fix netherite sword distribution.
Fix game completion when all remaining players are eliminated.
Allow entering more than two player names.
Netherite sword: fixed distribution so the sword is always placed in the player’s main hand; the previous item is moved to inventory or dropped.
Game ending: any active participant death now removes that player, correctly ending the game when one player remains.
Empty-game handling: added cleanup when all participants are eliminated.
Player names: the command already supports more than two players. Use:
Plain Text/knifeswap start Player1 Player2 Player3 Player4
package com.kodari.knifeswap;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
public final class KnifeSwapPlugin extends JavaPlugin {
private KnifeSwapGame game;
@Override
public void onEnable() {
KnifeItemFactory knifeItemFactory = new KnifeItemFactory(this);
this.game = new KnifeSwapGame(this, knifeItemFactory);
KnifeSwapCommand command = new KnifeSwapCommand(game);
if (getCommand("knifeswap") != null) {
getCommand("knifeswap").setExecutor(command);
getCommand("knifeswap").setTabCompleter(command);
}
Bukkit.getPluginManager().registerEvents(new KnifeSwapListener(game), this);
}
@Override
public void onDisable() {
if (game != null) {
game.stopSilently();
}
}
}