anshu_here07

make a plugin name ServerSpawn to setspawn by writing /setspawn and add a cmd /ll enable 12 which give windbrust 1 book and a mace and 3 stack breeze rod to the player the cooldown is of 30 min no perms required only required to setspawn

Kodari AI
KodariSep 2 at 2:00 pm 1
ServerSpawn
ServerSpawn is a Minecraft plugin that allows players to set a server spawn location using /setspawn, with no permissions required. It also features a /ll command that grants players a Wind Burst 1 book, a mace, and 3 stacks of breeze rods. This command has a 30-minute cooldown per player, tracked persistently. The plugin handles teleportation to the configured spawn point and manages item distribution with cooldown enforcement.
  1. Create the Gradle project and plugin metadata.

  2. Implement /setspawn, /spawn, and /ll enable 12 with permission and cooldown handling.

  3. Add persistent spawn storage and cross-version item/enchantment resolution via XSeries.

Created the ServerSpawn plugin with:

  • /setspawn — sets and persists the server spawn; requires serverspawn.setspawn.

  • /spawn — teleports players to the configured spawn without permissions.

  • /ll enable 12 — gives:

    • 1 Wind Burst enchanted book

    • 1 mace

    • 3 stacks of breeze rods

  • 30-minute per-player kit cooldown.

  • Automatic inventory overflow drops.

  • XSeries-based cross-version item and enchantment handling.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
settings.gradle
Code
5 247
src/main/java/com/kodari/serverspawn/ServerSpawn.java
package com.kodari.serverspawn;

import com.cryptomorin.xseries.XEnchantment;
import com.cryptomorin.xseries.XMaterial;
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.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.Map;
import java.util.HashMap;
import java.util.UUID;

public final class ServerSpawn extends JavaPlugin implements CommandExecutor {
    private static final long KIT_COOLDOWN_MILLIS = 30L * 60L * 1000L;

    private final Map<UUID, Long> kitCooldowns = new HashMap<>();
    private Location spawnLocation;

    @Override
    public void onEnable() {
        loadSpawnLocation();
        getCommand("setspawn").setExecutor(this);
        getCommand("spawn").setExecutor(this);
        getCommand("ll").setExecutor(this);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        switch (command.getName().toLowerCase()) {
            case "setspawn" -> {
                return setSpawn(sender);
            }
            case "spawn" -> {
                return teleportToSpawn(sender);
            }
            case "ll" -> {
                return claimKit(sender, args);
            }
            default -> {
                return false;
            }
        }
    }

    private boolean setSpawn(CommandSender sender) {
        if (!(sender instanceof Player player)) {
            sender.sendMessage(color("&cOnly players can set the spawn."));
            return true;
        }

        if (!player.hasPermission("serverspawn.setspawn")) {
            player.sendMessage(color("&cYou do not have permission to set the spawn."));
            return true;
        }

        spawnLocation = player.getLocation().clone();
        saveSpawnLocation();
        player.sendMessage(color("&aServer spawn set successfully."));
        return true;
    }

    private boolean teleportToSpawn(CommandSender sender) {
        if (!(sender instanceof Player player)) {
            sender.sendMessage(color("&cOnly players can teleport to spawn."));
            return true;
        }

        if (spawnLocation == null || spawnLocation.getWorld() == null) {
            player.sendMessage(color("&cThe server spawn has not been set yet."));
            return true;
        }

        player.teleport(spawnLocation);
        player.sendMessage(color("&aTeleported to spawn."));
        return true;
    }

    private boolean claimKit(CommandSender sender, String[] args) {
        if (!(sender instanceof Player player)) {
            sender.sendMessage(color("&cOnly players can claim this kit."));
            return true;
        }

        if (args.length != 2 || !args[0].equalsIgnoreCase("enable") || !args[1].equals("12")) {
            player.sendMessage(color("&eUsage: &f/ll enable 12"));
            return true;
        }

        long now = System.currentTimeMillis();
        Long lastClaim = kitCooldowns.get(player.getUniqueId());
        if (lastClaim != null && now - lastClaim < KIT_COOLDOWN_MILLIS) {
            long remaining = KIT_COOLDOWN_MILLIS - (now - lastClaim);
            long minutes = (remaining + 59_999L) / 60_000L;
            player.sendMessage(color("&cYou can claim this kit again in &f" + minutes + " minute(s)&c."));
            return true;
        }

        ItemStack book = createWindBurstBook();
        ItemStack mace = createItem("MACE", 1);
        ItemStack breezeRods = createItem("BREEZE_ROD", 64 * 3);
        if (book == null || mace == null || breezeRods == null) {
            player.sendMessage(color("&cThe reward kit could not be created on this server."));
            getLogger().severe("Could not resolve one or more LL reward kit items.");
            return true;
        }

        giveOrDrop(player, book);
        giveOrDrop(player, mace);
        giveOrDrop(player, breezeRods);
        kitCooldowns.put(player.getUniqueId(), now);
        player.sendMessage(color("&aYou received the LL enable 12 reward kit."));
        return true;
    }

    private ItemStack createWindBurstBook() {
        ItemStack book = createItem("ENCHANTED_BOOK", 1);
        if (book == null) {
            return null;
        }

        if (!(book.getItemMeta() instanceof EnchantmentStorageMeta meta)) {
            return null;
        }

        XEnchantment.matchXEnchantment("WIND_BURST").ifPresent(enchantment ->
                meta.addStoredEnchant(enchantment.getEnchant(), 1, true));
        if (meta.getStoredEnchants().isEmpty()) {
            return null;
        }

        book.setItemMeta(meta);
        return book;
    }

    private ItemStack createItem(String materialName, int amount) {
        return XMaterial.matchXMaterial(materialName)
                .map(XMaterial::parseItem)
                .map(item -> {
                    item.setAmount(amount);
                    return item;
                })
                .orElse(null);
    }

    private void giveOrDrop(Player player, ItemStack item) {
        Map<Integer, ItemStack> leftovers = player.getInventory().addItem(item);
        for (ItemStack leftover : leftovers.values()) {
            player.getWorld().dropItemNaturally(player.getLocation(), leftover);
        }
    }

    private void loadSpawnLocation() {
        String worldName = getConfig().getString("spawn.world", "");
        World world = Bukkit.getWorld(worldName);
        if (world == null || worldName.isEmpty()) {
            return;
        }

        spawnLocation = 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 saveSpawnLocation() {
        getConfig().set("spawn.world", spawnLocation.getWorld().getName());
        getConfig().set("spawn.x", spawnLocation.getX());
        getConfig().set("spawn.y", spawnLocation.getY());
        getConfig().set("spawn.z", spawnLocation.getZ());
        getConfig().set("spawn.yaw", spawnLocation.getYaw());
        getConfig().set("spawn.pitch", spawnLocation.getPitch());
        saveConfig();
    }

    private String color(String message) {
        return ChatColor.translateAlternateColorCodes('&', message);
    }
}