Skip to content

Commit

Permalink
Add validation for having at least one valid spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
haykam821 authored and Patbox committed Jan 1, 2025
1 parent 70a9415 commit 21029fe
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public static GameOpenProcedure open(GameOpenContext<GameConfig> context) {
throw new GameOpenException(Text.literal("Map couldn't load! @Patbox pls fix"), e);
}

map.validate();

RuntimeWorldConfig worldConfig = new RuntimeWorldConfig()
.setGenerator(map.asGenerator(context.server()))
.setTimeOfDay(config.map().time())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.jetbrains.annotations.Nullable;
import xyz.nucleoid.map_templates.BlockBounds;
import xyz.nucleoid.map_templates.TemplateRegion;
import xyz.nucleoid.plasmid.api.game.GameOpenException;
import xyz.nucleoid.plasmid.api.game.common.team.GameTeam;
import xyz.nucleoid.plasmid.api.game.common.team.GameTeamConfig;
import xyz.nucleoid.plasmid.api.game.common.team.GameTeamKey;
Expand Down Expand Up @@ -47,6 +48,11 @@ public BlockPos getRandomSpawnPos() {
public void setTeamRegions(List<BlockPos> spawn, float spawnYaw, List<TemplateRegion> monuments, Set<BlockBounds> classChange, GameMap map, GameConfig config) {
this.spawn = spawn;
this.spawnYaw = spawnYaw;

if (this.spawn.isEmpty()) {
throw new GameOpenException(Text.literal("No valid spawns for " + this.team.id()));
}

int id = 0;

for (var region : monuments) {
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/eu/pb4/destroythemonument/game/map/GameMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import eu.pb4.destroythemonument.game.data.TeamData;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import org.jetbrains.annotations.Nullable;
import xyz.nucleoid.map_templates.BlockBounds;
import xyz.nucleoid.plasmid.api.game.GameOpenException;
import xyz.nucleoid.plasmid.api.game.common.team.GameTeamKey;


Expand Down Expand Up @@ -44,6 +46,12 @@ public GameMap(MapConfig config, BlockBounds mapBounds) {

}

public void validate() {
if (this.validSpawn.isEmpty()) {
throw new GameOpenException(Text.literal("No valid waiting spawns"));
}
}

public abstract ChunkGenerator asGenerator(MinecraftServer server);

public boolean isUnbreakable(BlockPos block) {
Expand Down

0 comments on commit 21029fe

Please sign in to comment.