Initial commit: LoParkour v1.1.0

This commit is contained in:
loki 2026-02-24 22:07:03 +01:00
commit aecb03ccf8
120 changed files with 9668 additions and 0 deletions

View file

@ -0,0 +1,89 @@
package dev.loki.loparkour.generator;
import dev.loki.loparkour.LoParkour;
import dev.loki.loparkour.config.Config;
import dev.loki.loparkour.session.Session;
import dev.efnilite.vilib.schematic.Schematic;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.NoSuchElementException;
/**
* Spawn island handler.
*
* @author loki
* @since 5.0.0
*/
public final class Island {
/**
* The session.
*/
public final Session session;
/**
* The schematic.
*/
public final Schematic schematic;
/**
* The blocks that have been affected by the schematic.
*/
public List<Block> blocks;
public Island(@NotNull Session session, @Nullable Schematic schematic) {
this.session = session;
this.schematic = schematic;
}
/**
* Builds the island and teleports the player.
*/
public void build(Location location) {
if (schematic == null) {
return;
}
LoParkour.log("Building island");
blocks = schematic.paste(location.subtract(0, schematic.getDimensions().getY(), 0));
Material playerMaterial = Material.getMaterial(Config.GENERATION.getString("advanced.island.spawn.player-block").toUpperCase());
Material parkourMaterial = Material.getMaterial(Config.GENERATION.getString("advanced.island.parkour.begin-block").toUpperCase());
try {
Block player = blocks.stream().filter(block -> block.getType() == playerMaterial).findAny().orElseThrow();
Block parkour = blocks.stream().filter(block -> block.getType() == parkourMaterial).findAny().orElseThrow();
player.setType(Material.AIR);
parkour.setType(Material.AIR);
Location ps = player.getLocation().add(0.5, 0, 0.5);
ps.setYaw(Config.GENERATION.getInt("advanced.island.spawn.yaw"));
ps.setPitch(Config.GENERATION.getInt("advanced.island.spawn.pitch"));
session.generator.generateFirst(ps, parkour.getLocation().subtract(session.generator.heading).subtract(0, 1, 0));
session.generator.startTick();
session.getPlayers().forEach(pp -> pp.setup(ps));
} catch (NoSuchElementException ex) {
LoParkour.logging().stack("Error while trying to find parkour or player spawn in schematic %s".formatted(schematic.getFile().getName()),
"check if you used the same material as the one in generation.yml", ex);
blocks.forEach(block -> block.setType(Material.AIR));
}
}
/**
* Destroys the island.
*/
public void destroy() {
if (blocks == null) {
return;
}
blocks.forEach(block -> block.setType(Material.AIR, false));
}
}