NOT VOLVEX
📎 1 file 3,535 chars
📄
pasted-code-1789117126811.txt
txt 122 lines
▶
Create a complete, fully functional Java plugin for Minecraft (Spigot/Paper version 1.20+) based on the following logic and requirements. Provide all files including `plugin.yml`, `config.yml`, and complete Java source code.

---

### **1. Configuration (`config.yml`)**
Create a configurable spawn location in `config.yml`:
```yaml
main_spawn:
  world: "world"
  x: 0.0
  y: 64.0
  z: 0.0
  yaw: 0.0
  pitch: 0.0
2. Core Command: /sp [] []
Implement a /sp command with subcommands:

/sp invite 

If  argument is missing: Send §c[SP] Usage: /sp invite 

If target is offline: Send §c[SP] Ye player online nahi hai!

If sender targets themselves: Send §c[SP] Aap khud ko invite nahi kar sakte!

If sender and target are in the same world: Send §c[SP] Aap same world ke player ko invite nahi kar sakte!

Store the pending invite (Sender -> Target).

Send to sender: §a[SP] Aapne  ko invite bhej diya.

Send to target: §a[SP]  ne aapko spectate invite kiya hai! Accept ke liye §e/sp accept §alikhein.

/sp accept

If no pending invite exists for player: Send §c[SP] Aapko koi invite nahi aaya hai.

If host (inviter) is offline: Clear invite and send §c[SP] Invite bhejne wala player online nahi hai!

Accept logic:

Clear the pending invite.

Store spectating state: Player -> Host.

Teleport player to Host.

Set player's gamemode to SPECTATOR.

Send to player: §a[SP] Aap ab  ko spectate kar rahe hain!

/sp leave

If player is not spectating anyone: Send §c[SP] Aap abhi kisi ko spectate nahi kar rahe hain.

Leave logic:

Clear spectating state.

Set gamemode to SURVIVAL.

Teleport player to main_spawn location from config.yml.

Send to player: §e[SP] Aapne spectate chhod diya aur Spawn par teleport ho gaye.

/sp stop

Requires permission: sp.admin

If no permission: Send §c[SP] Permission nahi hai!

Loop through all online players:

If a player is spectating, clear their state, change gamemode to SURVIVAL, and teleport to main_spawn.

Send to admin: §c[SP] Sabhi spectating sessions stop kar diye gaye.

Default / Unknown Subcommand:

Send: §e[SP] Commands: /sp invite  | /sp accept | /sp leave

3. Event Listeners & Game Logic
Spectator Handler on Host Death (PlayerDeathEvent)

Check if any player was spectating the dying player (victim).

For each spectator watching the victim:

Send message: §c[SP] Match khatam! 3 second me Spawn par teleport ho rahe ho...

Delay 3 seconds (using BukkitRunnable/Scheduler).

Clear spectating state.

Change gamemode to SURVIVAL.

Teleport spectator to main_spawn.

Send message: §a[SP] Aap Spawn par pahunch gaye hain!

Victim Death & Respawn Teleport (PlayerRespawnEvent)

When any player dies and respawns (including the spectated player), automatically override their respawn location and force teleport them directly to main_spawn.

Quit Logic (PlayerQuitEvent)

Clean up pending invites involving the player.

If quitting player was a spectator:

Clear state, set gamemode to SURVIVAL, teleport to main_spawn.

If quitting player was being spectated by others:

For each spectator watching them: clear state, change gamemode to SURVIVAL, teleport to main_spawn, and send: §c[SP] Target offline chala gaya. Aap Spawn par bhej diye gaye hain.

4. Technical Constraints
Code should be clean, thread-safe, and well-structured using JavaPlugin, CommandExecutor, and Listener.

Use HashMap data structures to manage invitations and active spectator sessions.

Provide fully compile-ready code without placehold
Kodari AI
KodariSep 11 at 9:01 am 1
SpectateInvitePlugin
A Minecraft Spigot plugin enabling player spectation through invite-based sessions. Players can invite others to spectate them via /sp invite command, with accept and leave subcommands. Spectators are teleported to hosts, set to spectator gamemode, and returned to configured spawn on leave, host death, or quit. Includes admin stop command, pending invite management, spectator state tracking, and automatic cleanup on disconnects. Uses configurable spawn location and event listeners for death, respawn, and quit handling.

Created the complete SpectatePlugin project with:

  • Gradle build configuration for Paper 1.20.6+

  • plugin.yml and configurable config.yml

  • /sp invite, /sp accept, /sp leave, and /sp stop

  • Thread-safe invite and spectating state management

  • Death, respawn, and quit event handling

  • Delayed spectator teleportation after host death

  • Configurable main spawn teleportation

  • Admin permission support through sp.admin

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
8 387
src/main/java/com/kodari/spectate/SpectatePlugin.java
package com.kodari.spectate;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

public final class SpectatePlugin extends JavaPlugin {

    private SpectateManager spectateManager;

    @Override
    public void onEnable() {
        saveDefaultConfig();

        spectateManager = new SpectateManager();
        getCommand("sp").setExecutor(new SpCommand(this, spectateManager));
        Bukkit.getPluginManager().registerEvents(new SpListener(this, spectateManager), this);
    }

    public Location getMainSpawn() {
        String worldName = getConfig().getString("main_spawn.world", "world");
        World world = Bukkit.getWorld(worldName);
        if (world == null) {
            return null;
        }

        return new Location(
                world,
                getConfig().getDouble("main_spawn.x", 0.0),
                getConfig().getDouble("main_spawn.y", 64.0),
                getConfig().getDouble("main_spawn.z", 0.0),
                (float) getConfig().getDouble("main_spawn.yaw", 0.0),
                (float) getConfig().getDouble("main_spawn.pitch", 0.0)
        );
    }

    public void teleportToMainSpawn(Player player) {
        Location spawn = getMainSpawn();
        if (spawn != null) {
            player.teleport(spawn);
        }
    }
}