package com.spaceshipproject;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.util.BoundingBox;

/**
 * Représente un spaceship actuellement chargé dans le monde.
 * Stocké en table spaceships_loaded.
 */
public class LoadedSpaceship {

    private final long spaceshipId;
    private final String worldName;
    private final int originX;
    private final int originY;
    private final int originZ;
    private final int sizeX;
    private final int sizeY;
    private final int sizeZ;

    public LoadedSpaceship(long spaceshipId, String worldName,
                           int originX, int originY, int originZ,
                           int sizeX, int sizeY, int sizeZ) {
        this.spaceshipId = spaceshipId;
        this.worldName = worldName;
        this.originX = originX;
        this.originY = originY;
        this.originZ = originZ;
        this.sizeX = sizeX;
        this.sizeY = sizeY;
        this.sizeZ = sizeZ;
    }

    public long getSpaceshipId() { return spaceshipId; }
    public String getWorldName() { return worldName; }
    public int getOriginX() { return originX; }
    public int getOriginY() { return originY; }
    public int getOriginZ() { return originZ; }
    public int getSizeX() { return sizeX; }
    public int getSizeY() { return sizeY; }
    public int getSizeZ() { return sizeZ; }

    public World getWorld() {
        return Bukkit.getWorld(worldName);
    }

    public BoundingBox getBoundingBox() {
        return new BoundingBox(originX, originY, originZ,
                originX + sizeX, originY + sizeY, originZ + sizeZ);
    }

    public boolean contains(Location loc) {
        if (loc == null || loc.getWorld() == null) return false;
        if (!loc.getWorld().getName().equals(worldName)) return false;
        return getBoundingBox().contains(loc.toVector());
    }
}
