calmdev0499

Create a Paper Minecraft plugin called SpawnIsland.

The plugin must provide a /spawn command that teleports players to a configurable spawn-island location.

Commands

/spawn

* Teleports the player to the currently configured spawn location. * Works from anywhere in the server. * Uses the exact saved world, X, Y, Z, yaw, and pitch.

/setspawn

* Admin-only command. * Saves the admin’s current location as the new spawn location. * Saves the world, X, Y, Z, yaw, and pitch. * Sends a confirmation message showing that the spawn location was updated.

/spawn reload

* Admin-only command. * Reloads the plugin configuration without restarting the server.

Configuration

Store the spawn location in config.yml:

spawn: world: world x: 0.5 y: 100.0 z: 0.5 yaw: 0.0 pitch: 0.0

The plugin must automatically update these values when /setspawn is used.

Permissions

spawn.use spawn.admin

spawn.use allows /spawn.

spawn.admin allows /setspawn and /spawn reload.

Important behavior

* The spawn location must persist after a server restart. * Do not hardcode coordinates. * Do not hardcode the world name. * The /setspawn command must work in whatever world the admin is currently in. * If no spawn has been configured yet, /spawn should give the player a clear error instead of crashing. * Teleportation must preserve the configured yaw and pitch. * Make all messages configurable in config.yml. * Use normal Paper/Bukkit APIs and make the plugin compatible with the server’s current Paper version. * Do not add RTP or random teleportation. This plugin is specifically for /spawn and configuring the spawn-island destination.

Kodari AI
KodariOct 5 at 3:58 pm 1
SpawnIsland
A Paper Minecraft plugin providing a /spawn command that teleports players to a configurable spawn-island location. Admins use /setspawn to save their current position as the spawn point, storing world, coordinates, yaw, and pitch in config.yml. The /spawn reload command refreshes configuration without restarting. Spawn location persists across restarts. Permissions: spawn.use for /spawn, spawn.admin for /setspawn and reload. All messages are configurable. Teleportation preserves exact yaw and pitch. Clear error shown if no spawn is configured. Uses standard Paper/Bukkit APIs.
  1. Create the Paper Gradle project and plugin descriptor.

  2. Add configurable messages and an initially unconfigured spawn section.

  3. Implement /spawn, /spawn reload, and /setspawn with permission checks and persistent location data.

Created SpawnIsland with /spawn, admin-only /setspawn and /spawn reload, persistent configurable spawn coordinates, and configurable messages. The spawn starts unconfigured; /spawn displays a clear message until an admin sets it.

calmdev0499
📎 1 file 3,242 chars
📄
pasted-code-1791220715469.txt
txt 136 lines
▶
Fix the existing SpawnIsland Paper plugin.

The plugin currently has /spawn and /setspawn, but the commands are not working correctly. Rebuild/fix the command registration, permissions, configuration loading, and spawn-location saving.

1. Working spawn command

The plugin must register a configurable command that teleports the player to the saved spawn location.

Default command:

/spawn

When a player executes it:

* Teleport them to the saved spawn world.
* Use the exact X, Y, Z coordinates.
* Preserve the saved yaw and pitch.
* Work from anywhere in the server.
* Do not randomly teleport the player.
* Do not require the player to be near spawn.

2. Working set-spawn command

Default command:

/setspawn

When an administrator executes it:

* Save the administrator’s current world.
* Save X, Y, Z.
* Save yaw and pitch.
* Immediately save the values to config.yml.
* Make the new location available immediately without requiring a restart.

Example configuration:

spawn:
  world: world
  x: 0.5
  y: 100.0
  z: 0.5
  yaw: 0.0
  pitch: 0.0

3. Make command names configurable

Do NOT hardcode /spawn or /setspawn.

Add this to config.yml:

commands:
  spawn: "spawn"
  setspawn: "setspawn"
  reload: "spawnreload"

The plugin must register and use the configured command names.

For example, if I change:

commands:
  spawn: "hub"
  setspawn: "sethub"
  reload: "hubreload"

then the commands should become:

/hub
/sethub
/hubreload

The old command names should not remain active after the configuration is changed.

4. Reload command

Make the reload command configurable.

Default:

/spawnreload

It must reload config.yml and apply the new command settings and messages.

5. Permissions

Use:

spawn.use
spawn.admin

spawn.use:

* Allows the configured teleport command.

spawn.admin:

* Allows the configured set-spawn command.
* Allows the configured reload command.

Console should also be able to use administrative commands where appropriate.

6. Error handling

If a player uses the spawn command before a spawn location has been configured, send a clear configurable message instead of throwing an error.

If the saved world no longer exists, send a configurable error message instead of crashing.

7. Configurable messages

Add:

messages:
  spawn-set: "&aSpawn location successfully updated."
  teleported: "&aTeleported to spawn."
  no-spawn: "&cA spawn location has not been configured yet."
  no-permission: "&cYou don't have permission to use this command."
  reloaded: "&aSpawnIsland configuration reloaded."
  invalid-world: "&cThe configured spawn world could not be found."

8. Important

Make sure the plugin actually registers the commands with Paper/Bukkit.

The plugin must:

* Load without errors.
* Register commands correctly.
* Save the spawn location permanently.
* Create config.yml automatically if it doesn’t exist.
* Load the saved spawn location when the server starts.
* Work after a server restart.
* Never hardcode the spawn coordinates.
* Never hardcode the command names.
* Never add RTP functionality.

Also provide the corrected complete source code and all required files (plugin.yml, config.yml, Java classes, and build configuration) so the plugin can be compiled into a working .jar.
Kodari AI
KodariOct 5 at 5:20 pm 1
  1. Replace static plugin.yml commands with registration from commands in config, including removing the old labels on reload.

  2. Fix spawn loading/saving, teleport feedback, permissions, and the requested configurable error messages.

  3. Keep the existing Paper build setup and defaults in config.yml.

Updated SpawnIsland to register command names from config.yml, remove the previous configured names on reload, and use /spawnreload by default. Spawn location loading, persistence, permission checks, teleport feedback, and configurable errors are implemented; console can reload, while /setspawn reports that it is player-only.

Changed SpawnIslandPlugin.java, config.yml, and plugin.yml. The existing Paper Gradle build configuration remains unchanged.

calmdev0499

Fix the /setspawn command.

When a player uses /setspawn, the success message must be sent only to that player.

Do NOT use a broadcast, Bukkit.broadcastMessage(), or any server-wide message.

Correct behavior:

Player runs:

/setspawn

Only that player receives:

Spawn location successfully updated.

Other players online must receive nothing.

Also make sure /spawn only sends its teleport confirmation to the player who executed /spawn.

If the command is executed from the console, send the confirmation to the console instead of broadcasting it to players.

Keep the existing configurable messages in config.yml.

Kodari AI
KodariOct 5 at 5:37 pm 1

/setspawn and /spawn already send their success messages through sender.sendMessage(...); neither uses a broadcast. Players receive confirmations individually, and console invocations receive their sender-targeted response. Console cannot successfully set a player location or teleport itself, so those commands return the configured player-only message instead. No code change was needed.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
5 303
src/main/java/com/spawnisland/SpawnIslandPlugin.java
package com.spawnisland;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandMap;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

public final class SpawnIslandPlugin extends JavaPlugin {
    private final Map<String, Command> registeredCommands = new HashMap<>();
    private CommandMap commandMap;
    private Location configuredSpawn;
    private boolean spawnConfigured;
    private boolean spawnWorldMissing;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        loadSpawnLocation();
        registerConfiguredCommands();
    }

    private boolean handleSpawnCommand(CommandSender sender, String[] args) {
        if (args.length != 0) {
            sendMessage(sender, "usage");
            return true;
        }
        if (!sender.hasPermission("spawn.use")) {
            sendMessage(sender, "no-permission");
            return true;
        }
        if (!(sender instanceof org.bukkit.entity.Player player)) {
            sendMessage(sender, "player-only");
            return true;
        }

        if (!spawnConfigured) {
            sendMessage(sender, "no-spawn");
            return true;
        }
        if (spawnWorldMissing || configuredSpawn == null) {
            sendMessage(sender, "invalid-world");
            return true;
        }
        if (!player.teleport(configuredSpawn.clone())) {
            sendMessage(sender, "teleport-failed");
            return true;
        }
        sendMessage(sender, "teleported");
        return true;
    }

    private boolean handleSetSpawnCommand(CommandSender sender, String[] args) {
        if (!sender.hasPermission("spawn.admin")) {
            sendMessage(sender, "no-permission");
            return true;
        }
        if (!(sender instanceof org.bukkit.entity.Player player)) {
            sendMessage(sender, "player-only");
            return true;
        }
        if (args.length != 0) {
            sendMessage(sender, "usage");
            return true;
        }

        Location location = player.getLocation();
        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();
        configuredSpawn = location.clone();
        spawnConfigured = true;
        spawnWorldMissing = false;
        sendMessage(sender, "spawn-set");
        return true;
    }

    private boolean handleReloadCommand(CommandSender sender, String[] args) {
        if (!sender.hasPermission("spawn.admin")) {
            sendMessage(sender, "no-permission");
            return true;
        }
        if (args.length != 0) {
            sendMessage(sender, "usage");
            return true;
        }

        unregisterConfiguredCommands();
        reloadConfig();
        loadSpawnLocation();
        registerConfiguredCommands();
        sendMessage(sender, "reloaded");
        return true;
    }

    private void loadSpawnLocation() {
        spawnConfigured = getConfig().contains("spawn.world")
                && getConfig().contains("spawn.x")
                && getConfig().contains("spawn.y")
                && getConfig().contains("spawn.z")
                && getConfig().contains("spawn.yaw")
                && getConfig().contains("spawn.pitch");
        configuredSpawn = null;
        spawnWorldMissing = false;
        if (!spawnConfigured) {
            return;
        }

        String worldName = getConfig().getString("spawn.world");
        if (worldName == null || worldName.isBlank()) {
            spawnConfigured = false;
            return;
        }
        World world = Bukkit.getWorld(worldName);
        if (world == null) {
            spawnWorldMissing = true;
            return;
        }
        configuredSpawn = 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")
        );
    }

    private void registerConfiguredCommands() {
        commandMap = getCommandMap();
        if (commandMap == null) {
            getLogger().severe("Could not access Paper's command map; configured commands were not registered.");
            return;
        }

        registerConfiguredCommand("commands.spawn", "spawn.use", this::handleSpawnCommand);
        registerConfiguredCommand("commands.setspawn", "spawn.admin", this::handleSetSpawnCommand);
        registerConfiguredCommand("commands.reload", "spawn.admin", this::handleReloadCommand);
    }

    private void registerConfiguredCommand(String path, String permission, CommandAction action) {
        String name = getConfig().getString(path);
        if (name == null) {
            getLogger().warning("Missing command name at '" + path + "'; command not registered.");
            return;
        }
        name = name.trim().replaceFirst("^/+", "").toLowerCase(Locale.ROOT);
        if (!name.matches("[a-z0-9._-]+")) {
            getLogger().warning("Invalid command name at '" + path + "'; command not registered.");
            return;
        }
        if (registeredCommands.containsKey(name)) {
            getLogger().warning("Command name '" + name + "' is configured more than once; duplicate not registered.");
            return;
        }

        Command command = new ConfiguredCommand(name, permission, action);
        boolean registered = commandMap.register(getName().toLowerCase(Locale.ROOT), command);
        registeredCommands.put(name, command);
        if (!registered) {
            getLogger().warning("Command '" + name + "' conflicts with another command and may only be available with the plugin namespace.");
        }
    }

    private void unregisterConfiguredCommands() {
        if (commandMap == null || registeredCommands.isEmpty()) {
            registeredCommands.clear();
            return;
        }

        Set<Command> commands = new HashSet<>(registeredCommands.values());
        try {
            Field field = findKnownCommandsField(commandMap.getClass());
            field.setAccessible(true);
            Object value = field.get(commandMap);
            if (value instanceof Map<?, ?> knownCommands) {
                knownCommands.entrySet().removeIf(entry -> commands.contains(entry.getValue()));
            }
        } catch (ReflectiveOperationException | RuntimeException exception) {
            getLogger().severe("Could not unregister old configured commands: " + exception.getMessage());
        }
        for (Command command : commands) {
            command.unregister(commandMap);
        }
        registeredCommands.clear();
    }