Build a minimal, beginner-friendly Bukkit/Spigot Minecraft plugin that provides /spawn and /setspawn. Requirements: /setspawn saves the executing player's exact current location as the server spawn destination, persist it across restarts using the plugin's config.yml (world name, x/y/z, yaw, pitch), and only allow players with a clear permission such as simplespawn.setspawn to use /setspawn; default that permission to op in plugin.yml. /spawn teleports any player to the saved location, with friendly messages if spawn has not been set or the saved world is unavailable. Register both commands and permissions correctly; provide concise usage/success/denial messages, avoid unnecessary features, and follow this project's existing Bukkit API/version conventions. Inspect the starter project and implement all needed Java/resources, including plugin.yml/config defaults as appropriate. Do not build or claim build verification; done means implementation is complete.

Kodari AI
KodariOct 6 at 7:26 pm 1
SimpleSpawn
A minimal Bukkit/Spigot plugin providing /spawn and /setspawn commands. /setspawn saves the player's exact location (world, x/y/z, yaw, pitch) to config.yml, persisting across restarts, with permission simplespawn.setspawn defaulted to op. /spawn teleports any player to the saved location with friendly messages if unset or world unavailable. Commands and permissions registered in plugin.yml with concise usage, success, and denial messages. Beginner-friendly, no unnecessary features.
  1. Add the Bukkit plugin entry point for /spawn and permission-gated /setspawn.

  2. Add plugin metadata and persistent spawn defaults.

  3. Add minimal Gradle project configuration for the Spigot API.

Implemented SimpleSpawn with /spawn and op-only /setspawn. It persists the world, coordinates, yaw, and pitch in config.yml, and reports when spawn is unset or its world is unavailable. Added plugin metadata and minimal Spigot Gradle configuration; build verification was not run.

Extend the existing SimpleSpawn plugin (read current source before editing) with persistent last-location-on-rejoin behavior, retaining the existing /spawn and /setspawn features. Target Minecraft 1.21.1+ and explicitly support Purpur 1.21.1 via Bukkit/Spigot-compatible APIs only. Update build.gradle to compile against Spigot API 1.21.1 and Java 21; update plugin.yml api-version to '1.21' and plugin version as appropriate. On PlayerQuitEvent, save the player's exact current world and location (world identifier/name, x/y/z/yaw/pitch) keyed by UUID to a separate persistent YAML file in the plugin data folder (e.g. players.yml). On PlayerJoinEvent, if a saved location exists and its world is available, restore/teleport the player there so returning players do not land at server spawn; do not relocate first-time players without a saved location. Handle missing/unavailable world gracefully without throwing. Keep persistence across restarts and avoid losing player data when saving one player. Keep implementation small and use no NMS/Purpur-only API. Ensure plugin startup creates/loads the data file, registrations are correct, and code compiles against 1.21.1 APIs. Do not claim build verification or attempt to build; done means code/config changes complete.

Kodari AI
KodariOct 6 at 7:30 pm 1
  1. Inspect the current plugin and build metadata.

  2. Add UUID-keyed quit/join location persistence using Bukkit APIs and players.yml.

  3. Update Spigot 1.21.1 / Java 21 settings and plugin metadata.

Added quit/join location persistence in players.yml, keyed by UUID and including world, coordinates, yaw, and pitch. Returning players are restored when their saved world is available; first-time players are left at their normal join location, and unavailable worlds are handled with a message.

Updated the project to Spigot API 1.21.1, Java 21, and plugin API version 1.21. The implementation uses Bukkit-compatible APIs and is intended to support Purpur 1.21.1. Build verification was not run.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
5 208
src/main/java/com/example/simplespawn/SimpleSpawn.java
package com.example.simplespawn;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.io.IOException;

public class SimpleSpawn extends JavaPlugin implements CommandExecutor, Listener {
    private File playerLocationsFile;
    private FileConfiguration playerLocations;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        loadPlayerLocations();
        getCommand("spawn").setExecutor(this);
        getCommand("setspawn").setExecutor(this);
        getServer().getPluginManager().registerEvents(this, this);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (!(sender instanceof Player)) {
            sender.sendMessage(ChatColor.RED + "This command can only be used by a player.");
            return true;
        }

        Player player = (Player) sender;
        if (command.getName().equalsIgnoreCase("setspawn")) {
            if (!player.hasPermission("simplespawn.setspawn")) {
                player.sendMessage(ChatColor.RED + "You don't have permission to set the spawn.");
                return true;
            }

            saveSpawn(player);
            player.sendMessage(ChatColor.GREEN + "Server spawn set to your current location.");
            return true;
        }

        if (command.getName().equalsIgnoreCase("spawn")) {
            if (!getConfig().getBoolean("spawn.set")) {
                player.sendMessage(ChatColor.RED + "Spawn has not been set yet.");
                return true;
            }

            String worldName = getConfig().getString("spawn.world", "");
            World world = Bukkit.getWorld(worldName);
            if (world == null) {
                player.sendMessage(ChatColor.RED + "The saved spawn world is currently unavailable.");
                return true;
            }

            Location spawn = new Location(
                    world,
                    getConfig().getDouble("spawn.x"),
                    getConfig().getDouble("spawn.y"),
                    getConfig().getDouble("spawn.z"),
                    (float) getConfig().getDouble("spawn.yaw"),
                    (float) getConfig().getDouble("spawn.pitch")
            );
            player.teleport(spawn);
            player.sendMessage(ChatColor.GREEN + "Teleported to spawn.");
            return true;
        }

        return false;
    }

    @EventHandler
    public void onPlayerQuit(PlayerQuitEvent event) {
        Player player = event.getPlayer();
        Location location = player.getLocation();
        String path = player.getUniqueId().toString();

        playerLocations.set(path + ".world", location.getWorld().getName());
        playerLocations.set(path + ".x", location.getX());
        playerLocations.set(path + ".y", location.getY());
        playerLocations.set(path + ".z", location.getZ());
        playerLocations.set(path + ".yaw", location.getYaw());
        playerLocations.set(path + ".pitch", location.getPitch());
        savePlayerLocations();
    }

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        Player player = event.getPlayer();
        String path = player.getUniqueId().toString();
        if (!playerLocations.contains(path + ".world")) {
            return;
        }

        World world = Bukkit.getWorld(playerLocations.getString(path + ".world", ""));
        if (world == null) {
            player.sendMessage(ChatColor.RED + "Your saved location's world is currently unavailable.");
            return;
        }

        Location location = new Location(
                world,
                playerLocations.getDouble(path + ".x"),
                playerLocations.getDouble(path + ".y"),
                playerLocations.getDouble(path + ".z"),
                (float) playerLocations.getDouble(path + ".yaw"),
                (float) playerLocations.getDouble(path + ".pitch")
        );
        player.teleport(location);
    }

    private void loadPlayerLocations() {
        if (!getDataFolder().exists()) {
            getDataFolder().mkdirs();
        }

        playerLocationsFile = new File(getDataFolder(), "players.yml");
        if (!playerLocationsFile.exists()) {
            try {
                playerLocationsFile.createNewFile();
            } catch (IOException exception) {
                getLogger().severe("Could not create players.yml: " + exception.getMessage());
            }
        }
        playerLocations = YamlConfiguration.loadConfiguration(playerLocationsFile);
    }

    private void savePlayerLocations() {
        try {
            playerLocations.save(playerLocationsFile);
        } catch (IOException exception) {
            getLogger().severe("Could not save players.yml: " + exception.getMessage());
        }
    }

    private void saveSpawn(Player player) {
        Location location = player.getLocation();
        getConfig().set("spawn.set", true);
        getConfig().set("spawn.world", location.getWorld().getName());
        getConfig().set("spawn.x", location.getX());
        getConfig().set("spawn.y", location.getY());
        getConfig().set("spawn.z", location.getZ());
        getConfig().set("spawn.yaw", location.getYaw());
        getConfig().set("spawn.pitch", location.getPitch());
        saveConfig();
    }
}