feat: add multiple region support for mines
This commit is contained in:
parent
957468b6b6
commit
0f2735f171
8 changed files with 403 additions and 33 deletions
|
|
@ -2,33 +2,65 @@ package dev.loki.lomines.data.config.spawn;
|
|||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Configuration for player spawn location when stuck in blocks.
|
||||
* Configuration for player spawn locations when stuck in blocks.
|
||||
* Supports multiple spawn points for a single mine.
|
||||
* Used to teleport players out when they are suffocating after mine reset.
|
||||
*/
|
||||
public record PlayerSpawnConfig(
|
||||
boolean enabled,
|
||||
Location location
|
||||
) {
|
||||
public final class PlayerSpawnConfig {
|
||||
|
||||
public PlayerSpawnConfig {
|
||||
if (!enabled) {
|
||||
location = null;
|
||||
} else if (location != null) {
|
||||
// Defensive copy
|
||||
location = location.clone();
|
||||
Objects.requireNonNull(location.getWorld(), "Spawn world cannot be null");
|
||||
private final boolean enabled;
|
||||
private final List<Location> locations;
|
||||
|
||||
public PlayerSpawnConfig(boolean enabled, List<Location> locations) {
|
||||
this.enabled = enabled;
|
||||
if (!enabled || locations == null) {
|
||||
this.locations = List.of();
|
||||
} else {
|
||||
// Defensive copy with validation
|
||||
List<Location> copy = new ArrayList<>();
|
||||
for (Location loc : locations) {
|
||||
if (loc != null) {
|
||||
Location cloned = loc.clone();
|
||||
Objects.requireNonNull(cloned.getWorld(), "Spawn world cannot be null");
|
||||
copy.add(cloned);
|
||||
}
|
||||
}
|
||||
this.locations = List.copyOf(copy);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the spawn location if enabled.
|
||||
* Returns the primary spawn location (first in list) if enabled.
|
||||
*/
|
||||
public Optional<Location> getLocation() {
|
||||
return Optional.ofNullable(enabled ? location : null);
|
||||
return locations.isEmpty() ? Optional.empty() : Optional.of(locations.get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all spawn locations.
|
||||
*/
|
||||
public List<Location> getLocations() {
|
||||
return locations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if spawn is enabled and has at least one location.
|
||||
*/
|
||||
public boolean enabled() {
|
||||
return enabled && !locations.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of configured spawn locations.
|
||||
*/
|
||||
public int count() {
|
||||
return locations.size();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -39,9 +71,44 @@ public record PlayerSpawnConfig(
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates enabled config with location.
|
||||
* Creates enabled config with single location.
|
||||
*/
|
||||
public static PlayerSpawnConfig at(Location location) {
|
||||
return new PlayerSpawnConfig(true, location);
|
||||
return new PlayerSpawnConfig(true, List.of(location));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates enabled config with multiple locations.
|
||||
*/
|
||||
public static PlayerSpawnConfig at(List<Location> locations) {
|
||||
return new PlayerSpawnConfig(true, locations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new config with an additional location.
|
||||
*/
|
||||
public PlayerSpawnConfig addLocation(Location location) {
|
||||
List<Location> newList = new ArrayList<>(locations);
|
||||
newList.add(location);
|
||||
return new PlayerSpawnConfig(true, newList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new config without the location at given index.
|
||||
*/
|
||||
public PlayerSpawnConfig removeLocation(int index) {
|
||||
if (index < 0 || index >= locations.size()) {
|
||||
return this;
|
||||
}
|
||||
List<Location> newList = new ArrayList<>(locations);
|
||||
newList.remove(index);
|
||||
return new PlayerSpawnConfig(!newList.isEmpty(), newList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all locations (disables spawn).
|
||||
*/
|
||||
public PlayerSpawnConfig clear() {
|
||||
return disabled();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,32 +2,65 @@ package dev.loki.lomines.data.config.teleport;
|
|||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Configuration for mine teleportation on reset.
|
||||
* Supports multiple teleport locations for a single mine.
|
||||
*/
|
||||
public record TeleportConfig(
|
||||
boolean enabled,
|
||||
Location location
|
||||
) {
|
||||
public final class TeleportConfig {
|
||||
|
||||
public TeleportConfig {
|
||||
if (!enabled) {
|
||||
location = null;
|
||||
} else if (location != null) {
|
||||
// Defensive copy
|
||||
location = location.clone();
|
||||
Objects.requireNonNull(location.getWorld(), "Teleport world cannot be null");
|
||||
private final boolean enabled;
|
||||
private final List<Location> locations;
|
||||
|
||||
public TeleportConfig(boolean enabled, List<Location> locations) {
|
||||
this.enabled = enabled;
|
||||
if (!enabled || locations == null) {
|
||||
this.locations = List.of();
|
||||
} else {
|
||||
// Defensive copy with validation
|
||||
List<Location> copy = new ArrayList<>();
|
||||
for (Location loc : locations) {
|
||||
if (loc != null) {
|
||||
Location cloned = loc.clone();
|
||||
Objects.requireNonNull(cloned.getWorld(), "Teleport world cannot be null");
|
||||
copy.add(cloned);
|
||||
}
|
||||
}
|
||||
this.locations = List.copyOf(copy);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the teleport location if enabled.
|
||||
* Returns the primary teleport location (first in list) if enabled.
|
||||
*/
|
||||
public Optional<Location> getLocation() {
|
||||
return Optional.ofNullable(enabled ? location : null);
|
||||
return locations.isEmpty() ? Optional.empty() : Optional.of(locations.get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all teleport locations.
|
||||
*/
|
||||
public List<Location> getLocations() {
|
||||
return locations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if teleport is enabled and has at least one location.
|
||||
*/
|
||||
public boolean enabled() {
|
||||
return enabled && !locations.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of configured teleport locations.
|
||||
*/
|
||||
public int count() {
|
||||
return locations.size();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -38,9 +71,44 @@ public record TeleportConfig(
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates enabled config with location.
|
||||
* Creates enabled config with single location.
|
||||
*/
|
||||
public static TeleportConfig at(Location location) {
|
||||
return new TeleportConfig(true, location);
|
||||
return new TeleportConfig(true, List.of(location));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates enabled config with multiple locations.
|
||||
*/
|
||||
public static TeleportConfig at(List<Location> locations) {
|
||||
return new TeleportConfig(true, locations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new config with an additional location.
|
||||
*/
|
||||
public TeleportConfig addLocation(Location location) {
|
||||
List<Location> newList = new ArrayList<>(locations);
|
||||
newList.add(location);
|
||||
return new TeleportConfig(true, newList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new config without the location at given index.
|
||||
*/
|
||||
public TeleportConfig removeLocation(int index) {
|
||||
if (index < 0 || index >= locations.size()) {
|
||||
return this;
|
||||
}
|
||||
List<Location> newList = new ArrayList<>(locations);
|
||||
newList.remove(index);
|
||||
return new TeleportConfig(!newList.isEmpty(), newList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all locations (disables teleport).
|
||||
*/
|
||||
public TeleportConfig clear() {
|
||||
return disabled();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue