tower-generator #6
@ -2,31 +2,53 @@ tower:
|
||||
regions:
|
||||
1:
|
||||
minX: 0
|
||||
maxX: 0
|
||||
minZ: 69
|
||||
maxX: 69
|
||||
minZ: 0
|
||||
maxZ: 79
|
||||
escapeHeight: 1
|
||||
spawn:
|
||||
x: 66
|
||||
y: 23
|
||||
y: 25
|
||||
z: 71
|
||||
yaw: 180.0
|
||||
pitch: 0.0
|
||||
doors: []
|
||||
keys: []
|
||||
lavaY: 78
|
||||
laveSpace: 7
|
||||
lavaY: 76
|
||||
laveSpace: 9
|
||||
|
||||
towerGenerator:
|
||||
x: 0
|
||||
y: 12
|
||||
z: 0
|
||||
schematicType: steamtower
|
||||
fillRegions:
|
||||
1:
|
||||
minX: 28
|
||||
minZ: 30
|
||||
maxX: 33
|
||||
maxZ: 37
|
||||
percentage: 0.3
|
||||
material: MANGROVE_ROOTS
|
||||
2:
|
||||
minX: 36
|
||||
minZ: 47
|
||||
maxX: 42
|
||||
maxZ: 52
|
||||
percentage: 0.7
|
||||
material: MANGROVE_ROOTS
|
||||
3:
|
||||
minX: 29
|
||||
minZ: 43
|
||||
maxX: 36
|
||||
maxZ: 46
|
||||
percentage: 1.0
|
||||
material: MANGROVE_ROOTS
|
||||
|
||||
minX: -20
|
||||
maxX: 89
|
||||
minZ: -20
|
||||
maxZ: 99
|
||||
minX: -40
|
||||
maxX: 109
|
||||
minZ: -40
|
||||
maxZ: 119
|
||||
|
||||
winconditions:
|
||||
- LAST_REMAINING
|
||||
|
@ -24,6 +24,7 @@ import de.steamwar.towerrun.commands.StartCommand;
|
||||
import de.steamwar.towerrun.config.WorldConfig;
|
||||
import de.steamwar.towerrun.countdowns.EndCountdown;
|
||||
import de.steamwar.towerrun.countdowns.LobbyCountdown;
|
||||
import de.steamwar.towerrun.game.TowerRunGame;
|
||||
import de.steamwar.towerrun.generator.TowerGenerator;
|
||||
import de.steamwar.towerrun.listener.GlobalListener;
|
||||
import de.steamwar.towerrun.listener.IngameListener;
|
||||
@ -71,5 +72,7 @@ public class TowerRun extends JavaPlugin {
|
||||
final LobbyCountdown lobbyCountdown = new LobbyCountdown();
|
||||
new EndCountdown(lobbyCountdown);
|
||||
new StartCommand(lobbyCountdown);
|
||||
|
||||
TowerRunGame.reset();
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ import lombok.Getter;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.util.Vector;
|
||||
@ -162,7 +163,7 @@ public class WorldConfig {
|
||||
ACTIVE_WINCONDITIONS = config.getStringList("winconditions");
|
||||
WINCONDITIONS.stream().filter(winCondition -> ACTIVE_WINCONDITIONS.contains(winCondition.getName())).forEach(winCondition -> winCondition.setActive(true));
|
||||
|
||||
ConfigurationSection towerGeneratorSection = tower.getConfigurationSection("towerGenerator");
|
||||
ConfigurationSection towerGeneratorSection = config.getConfigurationSection("towerGenerator");
|
||||
if (towerGeneratorSection == null) {
|
||||
TOWER_GENERATOR_CONFIG = null;
|
||||
} else {
|
||||
@ -202,12 +203,46 @@ public class WorldConfig {
|
||||
public final int y;
|
||||
public final int z;
|
||||
public final SchematicType schematicType;
|
||||
public final TowerGeneratorFillRegion[] FILL_REGIONS;
|
||||
|
||||
public TowerGeneratorConfig(ConfigurationSection section) {
|
||||
x = section.getInt("x");
|
||||
y = section.getInt("y");
|
||||
z = section.getInt("z");
|
||||
schematicType = SchematicType.fromDB(section.getString("schematicType"));
|
||||
|
||||
ConfigurationSection fillRegionsSection = section.getConfigurationSection("fillRegions");
|
||||
if (fillRegionsSection != null) {
|
||||
List<ConfigurationSection> fillRegions = fillRegionsSection.getKeys(false).stream()
|
||||
.map(fillRegionsSection::getConfigurationSection)
|
||||
.toList();
|
||||
|
||||
FILL_REGIONS = new TowerGeneratorFillRegion[fillRegions.size()];
|
||||
for (int i = 0; i < fillRegions.size(); i++) {
|
||||
FILL_REGIONS[i] = new TowerGeneratorFillRegion(fillRegions.get(i));
|
||||
}
|
||||
} else {
|
||||
FILL_REGIONS = new TowerGeneratorFillRegion[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
public static final class TowerGeneratorFillRegion {
|
||||
private final int minX;
|
||||
private final int minZ;
|
||||
private final int maxX;
|
||||
private final int maxZ;
|
||||
private final double percentage;
|
||||
private final Material material;
|
||||
|
||||
public TowerGeneratorFillRegion(ConfigurationSection section) {
|
||||
minX = section.getInt("minX");
|
||||
minZ = section.getInt("minZ");
|
||||
maxX = section.getInt("maxX");
|
||||
maxZ = section.getInt("maxZ");
|
||||
percentage = section.getDouble("percentage");
|
||||
material = Material.valueOf(section.getString("material"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,6 +48,7 @@ public class LobbyCountdown extends Countdown {
|
||||
@Override
|
||||
void timerEnd() {
|
||||
TowerRunGame.prepareTower();
|
||||
override = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -65,7 +65,10 @@ public class TowerRunGame {
|
||||
private static void start() {
|
||||
if (GameState.getCurrentState() == GameStates.GENERATING_TOWER) {
|
||||
PLAYERS_ALIVE.addAll(TowerRunPlayer.getAll());
|
||||
PLAYERS_ALIVE.forEach(TowerRunPlayer::reset);
|
||||
PLAYERS_ALIVE.forEach(p -> {
|
||||
p.reset();
|
||||
p.player().setGameMode(GameMode.SURVIVAL);
|
||||
});
|
||||
GameState.nextState();
|
||||
generateLava();
|
||||
TowerRun.getMessage().broadcast("GAME_START");
|
||||
@ -125,7 +128,11 @@ public class TowerRunGame {
|
||||
resetWorld();
|
||||
GameState.reset();
|
||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||
if (TowerRun.getTowerGenerator() != null) {
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
} else {
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
}
|
||||
player.teleport(WorldConfig.SPAWN);
|
||||
});
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ public record TowerRunPlayer(Player player) {
|
||||
|
||||
public void reset() {
|
||||
if (TowerRun.getTowerGenerator() != null) {
|
||||
player.teleport(WorldConfig.SPAWN.add(0, TowerRun.getTowerGenerator().getHeight(), 0));
|
||||
player.teleport(WorldConfig.SPAWN.clone().add(0, TowerRun.getTowerGenerator().getHeight(), 0));
|
||||
} else {
|
||||
player.teleport(WorldConfig.SPAWN);
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import de.steamwar.towerrun.TowerRun;
|
||||
import de.steamwar.towerrun.config.WorldConfig;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.io.File;
|
||||
@ -28,9 +29,7 @@ import java.util.Random;
|
||||
public class TowerGenerator {
|
||||
|
||||
private Random random = new Random();
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
private WorldConfig.TowerGeneratorConfig config;
|
||||
private List<SchematicNode> ALL_SCHEMATICS;
|
||||
private Clipboard roof;
|
||||
|
||||
@ -38,10 +37,6 @@ public class TowerGenerator {
|
||||
private int height;
|
||||
|
||||
public TowerGenerator(WorldConfig.TowerGeneratorConfig config) {
|
||||
this(config.x, config.y, config.z, config.schematicType);
|
||||
}
|
||||
|
||||
public TowerGenerator(int x, int y, int z, SchematicType schematicType) {
|
||||
File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "Roof.schem");
|
||||
if (!file.exists()) {
|
||||
Bukkit.shutdown();
|
||||
@ -49,10 +44,8 @@ public class TowerGenerator {
|
||||
}
|
||||
roof = loadSchematic(file);
|
||||
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
ALL_SCHEMATICS = SchematicNode.getAllSchematicsOfType(schematicType);
|
||||
this.config = config;
|
||||
ALL_SCHEMATICS = SchematicNode.getAllSchematicsOfType(config.schematicType);
|
||||
}
|
||||
|
||||
private Clipboard loadSchematic(File file) {
|
||||
@ -69,7 +62,7 @@ public class TowerGenerator {
|
||||
public void generate(Runnable finishRunnable) {
|
||||
new BukkitRunnable() {
|
||||
int height = random.nextInt(50) + 200;
|
||||
int y = TowerGenerator.this.y;
|
||||
int y = TowerGenerator.this.config.y;
|
||||
|
||||
{
|
||||
TowerGenerator.this.height = height;
|
||||
@ -80,25 +73,45 @@ public class TowerGenerator {
|
||||
if (height > 0) {
|
||||
SchematicNode schematicNode = ALL_SCHEMATICS.get(random.nextInt(ALL_SCHEMATICS.size()));
|
||||
SchematicData schematicData = new SchematicData(schematicNode);
|
||||
int currentY;
|
||||
try {
|
||||
Clipboard clipboard = schematicData.load();
|
||||
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
|
||||
ClipboardHolder ch = new ClipboardHolder(clipboard);
|
||||
Operations.completeBlindly(ch.createPaste(e).to(BlockVector3.at(x, y, z)).build());
|
||||
Operations.completeBlindly(ch.createPaste(e).to(BlockVector3.at(config.x, y, config.z)).build());
|
||||
}
|
||||
currentY = y;
|
||||
y += clipboard.getDimensions().getY();
|
||||
height -= clipboard.getDimensions().getY();
|
||||
} catch (IOException e) {
|
||||
ALL_SCHEMATICS.remove(schematicNode);
|
||||
return;
|
||||
}
|
||||
|
||||
for (WorldConfig.TowerGeneratorFillRegion fillRegion : config.FILL_REGIONS) {
|
||||
for (int x = fillRegion.getMinX(); x < fillRegion.getMaxX(); x++) {
|
||||
for (int z = fillRegion.getMinZ(); z < fillRegion.getMaxZ(); z++) {
|
||||
for (int y = currentY; y < this.y; y++) {
|
||||
Block block = Bukkit.getWorlds().get(0).getBlockAt(x, y, z);
|
||||
if (!block.getType().isAir()) {
|
||||
continue;
|
||||
}
|
||||
if (random.nextDouble() < fillRegion.getPercentage()) {
|
||||
block.setType(fillRegion.getMaterial(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cancel();
|
||||
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
|
||||
ClipboardHolder ch = new ClipboardHolder(roof);
|
||||
Operations.completeBlindly(ch.createPaste(e).to(BlockVector3.at(x, y, z)).build());
|
||||
Operations.completeBlindly(ch.createPaste(e).to(BlockVector3.at(config.x, y, config.z)).build());
|
||||
}
|
||||
finishRunnable.run();
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(TowerRun.getInstance(), 0, 1);
|
||||
}.runTaskTimer(TowerRun.getInstance(), 0, 10);
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ public class IngameListener extends GameStateBukkitListener {
|
||||
@EventHandler
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
if (TowerRun.getTowerGenerator() != null) {
|
||||
event.setRespawnLocation(WorldConfig.SPAWN.add(0, TowerRun.getTowerGenerator().getHeight(), 0));
|
||||
event.setRespawnLocation(WorldConfig.SPAWN.clone().add(0, TowerRun.getTowerGenerator().getHeight(), 0));
|
||||
} else {
|
||||
event.setRespawnLocation(WorldConfig.SPAWN);
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import de.steamwar.towerrun.TowerRun;
|
||||
import de.steamwar.towerrun.config.WorldConfig;
|
||||
import de.steamwar.towerrun.state.GameStateBukkitListener;
|
||||
import de.steamwar.towerrun.state.GameStates;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -44,7 +45,7 @@ public class LobbyListener extends GameStateBukkitListener {
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (TowerRun.getTowerGenerator() != null) {
|
||||
player.teleport(WorldConfig.SPAWN.add(0, TowerRun.getTowerGenerator().getHeight(), 0));
|
||||
player.teleport(WorldConfig.SPAWN.clone().add(0, TowerRun.getTowerGenerator().getHeight(), 0));
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
} else {
|
||||
player.teleport(WorldConfig.SPAWN);
|
||||
@ -54,6 +55,9 @@ public class LobbyListener extends GameStateBukkitListener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
if (TowerRun.getTowerGenerator() != null) {
|
||||
return;
|
||||
}
|
||||
if(event.getTo().getY() < WorldConfig.SPAWN.getY() - 10) {
|
||||
event.getPlayer().teleport(WorldConfig.SPAWN);
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class NotLobbyListener extends GameStateBukkitListener {
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
event.getPlayer().setGameMode(GameMode.SPECTATOR);
|
||||
if (TowerRun.getTowerGenerator() != null) {
|
||||
event.getPlayer().teleport(WorldConfig.SPAWN.add(0, TowerRun.getTowerGenerator().getHeight(), 0));
|
||||
event.getPlayer().teleport(WorldConfig.SPAWN.clone().add(0, TowerRun.getTowerGenerator().getHeight(), 0));
|
||||
} else {
|
||||
event.getPlayer().teleport(WorldConfig.SPAWN);
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ public abstract class WinCondition extends GameStateBukkitListener {
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
if (active) {
|
||||
if (!active) {
|
||||
super.enable();
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren