- 
                Notifications
    You must be signed in to change notification settings 
- Fork 0
Spawn API usage
HomePlugin centralizes spawn operations behind a single facade: SpawnManager. It delegates to the active storage backend (YAML or SQL) so your code can remain storage‑agnostic.
- Preferred entry points:
- 
HomePlugin.getSpawnManager()— plugin-level accessor
- 
SpawnManager.getInstance()— static singleton
 
- 
- Backends are selected by plugin configuration. You can still interact with concrete managers when you need backend-specific control.
Related Javadoc:
| Backend | Manager Class | Package | Typical Use | 
|---|---|---|---|
| YAML (file) | SpawnYMLManager | fr.fuzeblocks.homeplugin.spawn.yml | Simplicity / single‑server | 
| MySQL | SpawnSQLManager | fr.fuzeblocks.homeplugin.spawn.sql | Networks / multi‑instance | 
Tip: Use the facade (SpawnManager) for most integrations. Reach for concrete managers only if you must control files, connections, or migrations.
Each method forwards to the active backend (YAML or SQL) with identical behavior.
- 
boolean setSpawn(Location location)
 Create or replace the spawn for theLocation’s world.
- 
Location getSpawn(World world)
 Retrieve the spawn location for a given world, ornullif none is defined.
- 
boolean hasSpawn(World world)
 Check whether a spawn exists for the world.
- 
boolean removeSpawn(World world)
 Delete the stored spawn for the world.
- 
boolean isStatus(Player player)
 Status flag (plugin‑specific; see Status/limits logic).
import fr.fuzeblocks.homeplugin.HomePlugin;
import fr.fuzeblocks.homeplugin.spawn.SpawnManager;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
SpawnManager spawns = HomePlugin.getSpawnManager(); // or SpawnManager.getInstance()
// Set the spawn for a world
Location hub = new Location(world, 0.5, 64, 0.5, 180f, 0f);
boolean set = spawns.setSpawn(hub);
// Query and teleport
World target = player.getWorld();
if (spawns.hasSpawn(target)) {
    Location spawnLoc = spawns.getSpawn(target);
    if (spawnLoc != null) {
        player.teleport(spawnLoc);
    }
}
// Remove
spawns.removeSpawn(target);- 
YAML - Package: fr.fuzeblocks.homeplugin.spawn.yml
- Class: SpawnYMLManager
- Constructor:
public SpawnYMLManager(File file) 
- Stores to a local YAML via YamlConfiguration.
- Javadoc: SpawnYMLManager
 
- Package: 
- 
MySQL - Package: fr.fuzeblocks.homeplugin.spawn.sql
- Class: SpawnSQLManager
- Persists to a SQL database; suited for multi‑server setups.
- Obtain via HomePlugin.getSpawnSQLManager().
- Javadoc: SpawnSQLManager
 
- Package: 
Use HomePlugin.getSpawnManager() unless you specifically need to operate the YAML file directly or manage SQL concerns.
- 
TaskManager.spawnTask(Player)— Utilities for delayed teleport flows.
- Events — Hook into lifecycle (e.g., spawn created/teleport). See Events doc.
- 
CacheManager— May cache spawn data indirectly through the plugin’s cache layer.
- Prefer HomePlugin.getSpawnManager()orSpawnManager.getInstance()to remain backend‑agnostic.
- The facade mirrors the backend methods:
- 
setSpawn(...),getSpawn(...),hasSpawn(...),removeSpawn(...),isStatus(...)
 
- 
- World scoping is unchanged (one spawn per world).
- 
isStatus(...)remains implementation‑specific; consult your status/limits policy before gating actions.
public void teleportToSpawn(Player player, World world) {
    var spawns = HomePlugin.getSpawnManager();
    if (spawns.hasSpawn(world)) {
        Location loc = spawns.getSpawn(world);
        if (loc != null) {
            player.teleport(loc);
            player.sendMessage("Teleported to world spawn.");
            return;
        }
    }
    player.sendMessage("No spawn set for this world.");
}Need migration helpers or event hooks around spawn changes? Ask and we’ll include a dedicated section.