Gaming Bharat

Make a minecraft spawn plugin in which the command for setting spawn is not /setspawn it is /setlsspawn and to get to that particular spawn point it is /lsspawn

Kodari AI
KodariOct 24 at 5:32 pm 1
LSSpawn
LSSpawn is a Minecraft Spigot plugin that provides custom spawn point management. It introduces two commands: /setlsspawn for server administrators to set the world spawn location, and /lsspawn for players to teleport to that designated spawn point. The plugin stores the spawn coordinates persistently in a configuration file, allowing the spawn to survive server restarts. It also includes permission nodes to control who can set the spawn and who can use the teleport command. Upon server startup, the plugin automatically loads the saved spawn location, ensuring seamless integration. The teleport command includes a safe location check to prevent players from spawning in unsafe blocks, and supports per-world spawn settings for multi-world servers.
  1. Add the Gradle project setup and plugin metadata.

  2. Implement /setlsspawn to save the sender’s location and /lsspawn to teleport players there.

Created the LSSpawn plugin. Use /setlsspawn to save your current location and /lsspawn to teleport there. Setting the spawn requires operator permission by default.

Gaming Bharat

Make a rtp plugin which randomly teleports the player anywhere in the world whose command is /lsrtp

Kodari AI
KodariOct 24 at 5:45 pm 1
  • Add /lsrtp while keeping the existing spawn commands.

  • Select a random spot within the player’s current world border, and teleport only onto a safe surface.

Added /lsrtp. It randomly teleports the player within their current world’s border, checking for a safe landing spot. The existing /setlsspawn and /lsspawn commands remain available.

Gaming Bharat

Also make another plugin which adds a gui to this rtp when used the command it opens a gui in which there is option for overworld or nether teleport

Kodari AI
KodariOct 24 at 5:48 pm 1
  • Change /lsrtp to open a two-option Overworld/Nether menu.

  • Add GUI click handling and safe random teleporting in the selected loaded world.

  • Add XSeries for version-safe GUI item icons.

Updated /lsrtp to open a GUI with Overworld and Nether options. Selecting one randomly teleports the player to a safe spot in the first loaded world of that type. Spawn commands remain unchanged.

Gaming Bharat

Update it by adding an option in the config file to change the world where the rtp teleports

Kodari AI
KodariOct 24 at 5:54 pm 1
  • Add separate configurable world names for the Overworld and Nether RTP options.

  • Resolve the selected option to that exact loaded world and report if it is missing or the wrong dimension.

Added rtp.overworld-world and rtp.nether-world to config.yml. Set each value to the name of the loaded world you want that /lsrtp menu option to use; it must match that option’s dimension type.

Gaming Bharat

Change the way the rtp teleprts it must check whether the place is safe or not and it must teleport to a safe place and teleports after a 5 second cooldown

Kodari AI
KodariOct 24 at 6:00 pm 1
  • Add a five-second pending RTP delay and prevent duplicate requests during it.

  • After the delay, search for a safe landing spot and teleport only if one is found.

Updated /lsrtp: it now waits 5 seconds before teleporting, blocks duplicate RTP requests during the wait, and checks for a safe landing spot—rejecting liquid, blocked spaces, and hazardous blocks—before teleporting.

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

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

public final class LSSpawnPlugin extends JavaPlugin implements Listener {

    private static final String RTP_MENU_TITLE = "Choose RTP World";
    private static final Set<String> HAZARDOUS_BLOCKS = Set.of(
            "CACTUS", "MAGMA_BLOCK", "CAMPFIRE", "SOUL_CAMPFIRE", "FIRE", "SOUL_FIRE",
            "POWDER_SNOW", "SWEET_BERRY_BUSH", "WITHER_ROSE", "POINTED_DRIPSTONE"
    );
    private final Set<UUID> pendingRtp = new HashSet<>();

    @Override
    public void onEnable() {
        saveDefaultConfig();
        getServer().getPluginManager().registerEvents(this, this);
    }

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (command.getName().equalsIgnoreCase("setlsspawn")) {
            if (!(sender instanceof Player player)) {
                sender.sendMessage("Only a player can set the LSSpawn destination.");
                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();
            player.sendMessage("LSSpawn destination set to your current location.");
            return true;
        }

        if (command.getName().equalsIgnoreCase("lsspawn")) {
            if (!(sender instanceof Player player)) {
                sender.sendMessage("Only a player can use /lsspawn.");
                return true;
            }

            Location spawn = getSpawnLocation();
            if (spawn == null) {
                player.sendMessage("The LSSpawn destination has not been set yet.");
                return true;
            }

            player.teleport(spawn);
            player.sendMessage("Teleported to LSSpawn.");
            return true;
        }

        if (command.getName().equalsIgnoreCase("lsrtp")) {
            if (!(sender instanceof Player player)) {
                sender.sendMessage("Only a player can use /lsrtp.");
                return true;
            }

            openRtpMenu(player);
            return true;
        }

        return false;
    }

    private void openRtpMenu(Player player) {
        Inventory inventory = Bukkit.createInventory(null, 9, RTP_MENU_TITLE);
        inventory.setItem(2, createWorldButton("GRASS_BLOCK", ChatColor.GREEN + "Overworld"));
        inventory.setItem(6, createWorldButton("NETHERRACK", ChatColor.DARK_RED + "Nether"));
        player.openInventory(inventory);
    }

    private ItemStack createWorldButton(String materialName, String displayName) {
        ItemStack item = new ItemStack(Material.matchMaterial(materialName));
        ItemMeta meta = item.getItemMeta();
        meta.setDisplayName(displayName);
        item.setItemMeta(meta);
        return item;
    }

    @EventHandler
    public void onRtpMenuClick(InventoryClickEvent event) {
        if (!RTP_MENU_TITLE.equals(event.getView().getTitle())) {
            return;
        }

        event.setCancelled(true);
        if (event.getClickedInventory() != event.getView().getTopInventory()
                || !(event.getWhoClicked() instanceof Player player)) {
            return;
        }

        World.Environment environment;
        if (event.getSlot() == 2) {
            environment = World.Environment.NORMAL;
        } else if (event.getSlot() == 6) {
            environment = World.Environment.NETHER;
        } else {
            return;
        }

        player.closeInventory();
        World world = getWorldByEnvironment(environment);
        if (world == null) {
            player.sendMessage(environment == World.Environment.NETHER
                    ? "No loaded Nether world was found."
                    : "No loaded Overworld was found.");
            return;
        }

        if (!pendingRtp.add(player.getUniqueId())) {
            player.sendMessage("An RTP is already counting down.");
            return;
        }

        player.sendMessage("Random teleporting in 5 seconds...");
        Bukkit.getScheduler().runTaskLater(this, () -> {
            pendingRtp.remove(player.getUniqueId());
            if (!player.isOnline()) {
                return;
            }

            if (teleportRandomly(player, world)) {
                player.sendMessage("You were randomly teleported to the "
                        + (environment == World.Environment.NETHER ? "Nether." : "Overworld."));
            } else {
                player.sendMessage("Could not find a safe random location. Try again.");
            }
        }, 100L);
    }

    private World getWorldByEnvironment(World.Environment environment) {
        String configPath = environment == World.Environment.NETHER
                ? "rtp.nether-world"
                : "rtp.overworld-world";
        String worldName = getConfig().getString(configPath);
        if (worldName == null) {
            return null;
        }

        World world = Bukkit.getWorld(worldName);
        return world != null && world.getEnvironment() == environment ? world : null;
    }

    private boolean teleportRandomly(Player player, World world) {
        var border = world.getWorldBorder();
        double halfSize = border.getSize() / 2.0;
        double minX = Math.max(border.getCenter().getX() - halfSize + 2, -29_999_998);
        double maxX = Math.min(border.getCenter().getX() + halfSize - 2, 29_999_998);
        double minZ = Math.max(border.getCenter().getZ() - halfSize + 2, -29_999_998);
        double maxZ = Math.min(border.getCenter().getZ() + halfSize - 2, 29_999_998);
        if (minX >= maxX || minZ >= maxZ) {
            return false;
        }

        ThreadLocalRandom random = ThreadLocalRandom.current();
        for (int attempt = 0; attempt < 30; attempt++) {
            int x = (int) Math.floor(random.nextDouble(minX, maxX));
            int z = (int) Math.floor(random.nextDouble(minZ, maxZ));
            int highestY = Math.min(world.getHighestBlockYAt(x, z), world.getMaxHeight() - 3);
            for (int y = highestY; y >= world.getMinHeight() + 1; y--) {
                Block ground = world.getBlockAt(x, y, z);
                Block feet = world.getBlockAt(x, y + 1, z);
                Block head = world.getBlockAt(x, y + 2, z);
                if (!ground.getType().isSolid() || ground.isLiquid()
                        || !feet.isPassable() || feet.isLiquid()
                        || !head.isPassable() || head.isLiquid()
                        || isHazardous(ground) || isHazardous(feet) || isHazardous(head)) {
                    continue;
                }

                Location destination = new Location(world, x + 0.5, y + 1, z + 0.5,
                        player.getLocation().getYaw(), player.getLocation().getPitch());
                if (player.teleport(destination)) {
                    return true;
                }