trigger_god
📎 1 file 2,638 chars
📄
pasted-code-1772624224673.txt
txt 125 lines
▶
Create a Minecraft Spigot/Paper plugin (Java) with the following functionality.

Plugin Name: LobbySpawn

Compatibility:

- Paper / Spigot 1.20+
- Java 17

Commands:

1. /setspawn

- Only OP players can run this command.
- Saves the player's current location (world, x, y, z, yaw, pitch) as the server spawn.
- Save this location inside "config.yml".

2. /spawn

- Available to all players.
- Teleports the player to the saved spawn location.
- Teleport is not instant and takes 5 seconds.

Spawn Teleport System:

3. Teleport Countdown

- When "/spawn" is used:
  
  - Start a 5 second countdown.
  - Show a message in the action bar like:
  
  Teleporting in 5...
  Teleporting in 4...
  Teleporting in 3...
  Teleporting in 2...
  Teleporting in 1...

- After the countdown reaches 0, teleport the player to spawn.

4. Movement Cancel

- If the player moves position (changes X or Z block) during the countdown, the teleport must be cancelled.
- Looking around (changing yaw or pitch) should NOT cancel the teleport.

5. Damage Rules

- If the player takes damage from a mob, fall damage, or environment, the teleport should NOT cancel.
- If the player moves after taking damage, it cancels normally.

Combat System:

6. Combat Restriction

- If a player is in combat with another player, they cannot use /spawn.

- If they try, show message:
  "You cannot use /spawn while in combat!"

- A player is considered in combat for 10 seconds after:
  
  - damaging another player
  - being damaged by another player

- Combat should be tracked using EntityDamageByEntityEvent.

Join Behavior:

7. First Join

- When a player joins the server for the first time:
  - Teleport them to spawn
  - Send message:
    "Welcome to the server, !"
  - Spawn a firework effect at the player location.

8. Welcome Back Message

- If a player joins and their last login was more than 12 hours ago, send:
  "Welcome back, ! We missed you."

Lobby World Logic:

9. slobby World Behavior

- If a player logs out while in world "slobby", when they rejoin they should be teleported to spawn.

10. Other Worlds

- If a player logs out in any world other than "slobby", they should rejoin at their last location normally.

Configuration:

Example "config.yml":

spawn:
  world: world
  x: 0
  y: 64
  z: 0
  yaw: 0
  pitch: 0

Events Required:

- PlayerJoinEvent
- PlayerMoveEvent
- EntityDamageByEntityEvent
- PlayerQuitEvent

Files to Generate:
Provide full code for:

- Main plugin class
- Spawn command class
- SetSpawn command class
- Event listener class
- plugin.yml
- config.yml

plugin.yml must include:
Commands:

- /setspawn
- /spawn
Kodari AI
KodariMar 4 at 11:39 am 14,401 (v2)

I’ll create a comprehensive LobbySpawn plugin with combat-aware teleportation and smart join behavior.

LobbySpawn
A lobby spawn management system featuring combat-aware teleportation with countdown timers, movement detection, first-join welcome system with fireworks, world-specific respawn logic for lobby worlds, and automatic cleanup of combat and teleport states. Supports delayed spawn teleportation with action bar countdown display.

All files created! The LobbySpawn plugin features:

  • Combat system: 10-second combat tag prevents /spawn usage when fighting players

  • Teleport countdown: 5-second delay with action bar display, cancels on horizontal movement (X/Z)

  • First join: Welcome message + firework effect at spawn

  • Welcome back: Message for players returning after 12+ hours

  • World logic: Players in “slobby” world respawn at spawn on rejoin

  • Data persistence: Saves spawn location and last-logout world in config.yml

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
8 477
src/main/java/com/lobbyspawn/LobbySpawn.java
package com.lobbyspawn;

import com.lobbyspawn.commands.SetSpawnCommand;
import com.lobbyspawn.commands.SpawnCommand;
import com.lobbyspawn.listeners.PlayerListener;
import com.lobbyspawn.tasks.TeleportTask;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

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

@Getter
public class LobbySpawn extends JavaPlugin {
    
    private final Map<UUID, Long> combatMap = new HashMap<>();
    private final Map<UUID, TeleportTask> teleportTasks = new HashMap<>();
    private final Map<UUID, String> lastWorldMap = new HashMap<>();
    
    @Override
    public void onEnable() {
        saveDefaultConfig();
        loadPlayerData();
        
        getCommand("setspawn").setExecutor(new SetSpawnCommand(this));
        getCommand("spawn").setExecutor(new SpawnCommand(this));
        
        Bukkit.getPluginManager().registerEvents(new PlayerListener(this), this);
        
        getLogger().info("LobbySpawn has been enabled!");
    }
    
    @Override
    public void onDisable() {
        savePlayerData();
        
        for (TeleportTask task : teleportTasks.values()) {
            task.cancel();
        }
        teleportTasks.clear();
        combatMap.clear();
        
        getLogger().info("LobbySpawn has been disabled!");
    }
    
    public Location getSpawnLocation() {
        FileConfiguration config = getConfig();
        
        if (!config.contains("spawn.world")) {
            return null;
        }
        
        String worldName = config.getString("spawn.world");
        double x = config.getDouble("spawn.x");
        double y = config.getDouble("spawn.y");
        double z = config.getDouble("spawn.z");
        float yaw = (float) config.getDouble("spawn.yaw");
        float pitch = (float) config.getDouble("spawn.pitch");
        
        org.bukkit.World world = Bukkit.getWorld(worldName);
        if (world == null) {
            return null;
        }
        
        return new Location(world, x, y, z, yaw, pitch);
    }
    
    public void setSpawnLocation(Location location) {
        FileConfiguration config = getConfig();
        
        config.set("spawn.world", location.getWorld().getName());
        config.set("spawn.x", location.getX());
        config.set("spawn.y", location.getY());
        config.set("spawn.z", location.getZ());
        config.set("spawn.yaw", location.getYaw());
        config.set("spawn.pitch", location.getPitch());
        
        saveConfig();
    }
    
    public boolean isInCombat(UUID playerId) {
        if (!combatMap.containsKey(playerId)) {
            return false;
        }
        
        long combatEnd = combatMap.get(playerId);
        if (System.currentTimeMillis() >= combatEnd) {
            combatMap.remove(playerId);
            return false;
        }
        
        return true;
    }
    
    public void tagCombat(UUID playerId) {
        combatMap.put(playerId, System.currentTimeMillis() + 10000);
    }
    
    public void removeCombat(UUID playerId) {
        combatMap.remove(playerId);
    }
    
    public void cancelTeleport(UUID playerId) {
        TeleportTask task = teleportTasks.remove(playerId);
        if (task != null) {
            task.cancel();
        }
    }
    
    public String getLastWorld(UUID playerId) {
        return lastWorldMap.get(playerId);
    }
    
    public void setLastWorld(UUID playerId, String worldName) {
        lastWorldMap.put(playerId, worldName);
    }
    
    private void loadPlayerData() {
        FileConfiguration config = getConfig();
        
        if (config.contains("playerData")) {
            for (String uuidString : config.getConfigurationSection("playerData").getKeys(false)) {
                try {
                    UUID uuid = UUID.fromString(uuidString);
                    String world = config.getString("playerData." + uuidString);
                    lastWorldMap.put(uuid, world);
                } catch (IllegalArgumentException e) {
                    getLogger().warning("Invalid UUID in playerData: " + uuidString);
                }
            }
        }
    }
    
    private void savePlayerData() {
        FileConfiguration config = getConfig();
        
        config.set("playerData", null);
        
        for (Map.Entry<UUID, String> entry : lastWorldMap.entrySet()) {
            config.set("playerData." + entry.getKey().toString(), entry.getValue());
        }
        
        saveConfig();
    }
}