Archiviert
13
0

tower-generator #6

Zusammengeführt
YoyoNow hat 16 Commits von tower-generator nach master 2023-09-23 21:29:06 +02:00 zusammengeführt
11 geänderte Dateien mit 117 neuen und 32 gelöschten Zeilen
Nur Änderungen aus Commit 0e9ba50cde werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -2,31 +2,53 @@ tower:
regions: regions:
1: 1:
minX: 0 minX: 0
maxX: 0 maxX: 69
minZ: 69 minZ: 0
maxZ: 79 maxZ: 79
escapeHeight: 1 escapeHeight: 1
spawn: spawn:
x: 66 x: 66
y: 23 y: 25
z: 71 z: 71
yaw: 180.0 yaw: 180.0
pitch: 0.0 pitch: 0.0
doors: [] doors: []
keys: [] keys: []
lavaY: 78 lavaY: 76
laveSpace: 7 laveSpace: 9
towerGenerator: towerGenerator:
x: 0 x: 0
y: 12 y: 12
z: 0 z: 0
schematicType: steamtower 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 minX: -40
maxX: 89 maxX: 109
minZ: -20 minZ: -40
maxZ: 99 maxZ: 119
winconditions: winconditions:
- LAST_REMAINING - LAST_REMAINING

Datei anzeigen

@ -24,6 +24,7 @@ import de.steamwar.towerrun.commands.StartCommand;
import de.steamwar.towerrun.config.WorldConfig; import de.steamwar.towerrun.config.WorldConfig;
import de.steamwar.towerrun.countdowns.EndCountdown; import de.steamwar.towerrun.countdowns.EndCountdown;
import de.steamwar.towerrun.countdowns.LobbyCountdown; import de.steamwar.towerrun.countdowns.LobbyCountdown;
import de.steamwar.towerrun.game.TowerRunGame;
import de.steamwar.towerrun.generator.TowerGenerator; import de.steamwar.towerrun.generator.TowerGenerator;
import de.steamwar.towerrun.listener.GlobalListener; import de.steamwar.towerrun.listener.GlobalListener;
import de.steamwar.towerrun.listener.IngameListener; import de.steamwar.towerrun.listener.IngameListener;
@ -71,5 +72,7 @@ public class TowerRun extends JavaPlugin {
final LobbyCountdown lobbyCountdown = new LobbyCountdown(); final LobbyCountdown lobbyCountdown = new LobbyCountdown();
new EndCountdown(lobbyCountdown); new EndCountdown(lobbyCountdown);
new StartCommand(lobbyCountdown); new StartCommand(lobbyCountdown);
TowerRunGame.reset();
} }
} }

Datei anzeigen

@ -29,6 +29,7 @@ import lombok.Getter;
import lombok.experimental.UtilityClass; import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
@ -162,7 +163,7 @@ public class WorldConfig {
ACTIVE_WINCONDITIONS = config.getStringList("winconditions"); ACTIVE_WINCONDITIONS = config.getStringList("winconditions");
WINCONDITIONS.stream().filter(winCondition -> ACTIVE_WINCONDITIONS.contains(winCondition.getName())).forEach(winCondition -> winCondition.setActive(true)); 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) { if (towerGeneratorSection == null) {
TOWER_GENERATOR_CONFIG = null; TOWER_GENERATOR_CONFIG = null;
} else { } else {
@ -202,12 +203,46 @@ public class WorldConfig {
public final int y; public final int y;
public final int z; public final int z;
public final SchematicType schematicType; public final SchematicType schematicType;
public final TowerGeneratorFillRegion[] FILL_REGIONS;
public TowerGeneratorConfig(ConfigurationSection section) { public TowerGeneratorConfig(ConfigurationSection section) {
x = section.getInt("x"); x = section.getInt("x");
y = section.getInt("y"); y = section.getInt("y");
z = section.getInt("z"); z = section.getInt("z");
schematicType = SchematicType.fromDB(section.getString("schematicType")); 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"));
} }
} }
} }

Datei anzeigen

@ -48,6 +48,7 @@ public class LobbyCountdown extends Countdown {
@Override @Override
void timerEnd() { void timerEnd() {
TowerRunGame.prepareTower(); TowerRunGame.prepareTower();
override = false;
} }
@Override @Override

Datei anzeigen

@ -65,7 +65,10 @@ public class TowerRunGame {
private static void start() { private static void start() {
if (GameState.getCurrentState() == GameStates.GENERATING_TOWER) { if (GameState.getCurrentState() == GameStates.GENERATING_TOWER) {
PLAYERS_ALIVE.addAll(TowerRunPlayer.getAll()); PLAYERS_ALIVE.addAll(TowerRunPlayer.getAll());
PLAYERS_ALIVE.forEach(TowerRunPlayer::reset); PLAYERS_ALIVE.forEach(p -> {
p.reset();
p.player().setGameMode(GameMode.SURVIVAL);
});
GameState.nextState(); GameState.nextState();
generateLava(); generateLava();
TowerRun.getMessage().broadcast("GAME_START"); TowerRun.getMessage().broadcast("GAME_START");
@ -125,7 +128,11 @@ public class TowerRunGame {
resetWorld(); resetWorld();
GameState.reset(); GameState.reset();
Bukkit.getOnlinePlayers().forEach(player -> { Bukkit.getOnlinePlayers().forEach(player -> {
if (TowerRun.getTowerGenerator() != null) {
player.setGameMode(GameMode.SPECTATOR);
} else {
player.setGameMode(GameMode.SURVIVAL); player.setGameMode(GameMode.SURVIVAL);
}
player.teleport(WorldConfig.SPAWN); player.teleport(WorldConfig.SPAWN);
}); });
} }

Datei anzeigen

@ -45,7 +45,7 @@ public record TowerRunPlayer(Player player) {
public void reset() { public void reset() {
if (TowerRun.getTowerGenerator() != null) { 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 { } else {
player.teleport(WorldConfig.SPAWN); player.teleport(WorldConfig.SPAWN);
} }

Datei anzeigen

@ -16,6 +16,7 @@ import de.steamwar.towerrun.TowerRun;
import de.steamwar.towerrun.config.WorldConfig; import de.steamwar.towerrun.config.WorldConfig;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import java.io.File; import java.io.File;
@ -28,9 +29,7 @@ import java.util.Random;
public class TowerGenerator { public class TowerGenerator {
private Random random = new Random(); private Random random = new Random();
private int x; private WorldConfig.TowerGeneratorConfig config;
private int y;
private int z;
private List<SchematicNode> ALL_SCHEMATICS; private List<SchematicNode> ALL_SCHEMATICS;
private Clipboard roof; private Clipboard roof;
@ -38,10 +37,6 @@ public class TowerGenerator {
private int height; private int height;
public TowerGenerator(WorldConfig.TowerGeneratorConfig config) { 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"); File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "Roof.schem");
if (!file.exists()) { if (!file.exists()) {
Bukkit.shutdown(); Bukkit.shutdown();
@ -49,10 +44,8 @@ public class TowerGenerator {
} }
roof = loadSchematic(file); roof = loadSchematic(file);
this.x = x; this.config = config;
this.y = y; ALL_SCHEMATICS = SchematicNode.getAllSchematicsOfType(config.schematicType);
this.z = z;
ALL_SCHEMATICS = SchematicNode.getAllSchematicsOfType(schematicType);
} }
private Clipboard loadSchematic(File file) { private Clipboard loadSchematic(File file) {
@ -69,7 +62,7 @@ public class TowerGenerator {
public void generate(Runnable finishRunnable) { public void generate(Runnable finishRunnable) {
new BukkitRunnable() { new BukkitRunnable() {
int height = random.nextInt(50) + 200; int height = random.nextInt(50) + 200;
int y = TowerGenerator.this.y; int y = TowerGenerator.this.config.y;
{ {
TowerGenerator.this.height = height; TowerGenerator.this.height = height;
@ -80,25 +73,45 @@ public class TowerGenerator {
if (height > 0) { if (height > 0) {
SchematicNode schematicNode = ALL_SCHEMATICS.get(random.nextInt(ALL_SCHEMATICS.size())); SchematicNode schematicNode = ALL_SCHEMATICS.get(random.nextInt(ALL_SCHEMATICS.size()));
SchematicData schematicData = new SchematicData(schematicNode); SchematicData schematicData = new SchematicData(schematicNode);
int currentY;
try { try {
Clipboard clipboard = schematicData.load(); Clipboard clipboard = schematicData.load();
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) { try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
ClipboardHolder ch = new ClipboardHolder(clipboard); 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(); y += clipboard.getDimensions().getY();
height -= clipboard.getDimensions().getY(); height -= clipboard.getDimensions().getY();
} catch (IOException e) { } catch (IOException e) {
ALL_SCHEMATICS.remove(schematicNode); 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 { } else {
cancel();
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) { try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
ClipboardHolder ch = new ClipboardHolder(roof); 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(); finishRunnable.run();
} }
} }
}.runTaskTimer(TowerRun.getInstance(), 0, 1); }.runTaskTimer(TowerRun.getInstance(), 0, 10);
} }
} }

Datei anzeigen

@ -113,7 +113,7 @@ public class IngameListener extends GameStateBukkitListener {
@EventHandler @EventHandler
public void onPlayerRespawn(PlayerRespawnEvent event) { public void onPlayerRespawn(PlayerRespawnEvent event) {
if (TowerRun.getTowerGenerator() != null) { 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 { } else {
event.setRespawnLocation(WorldConfig.SPAWN); event.setRespawnLocation(WorldConfig.SPAWN);
} }

Datei anzeigen

@ -23,6 +23,7 @@ import de.steamwar.towerrun.TowerRun;
import de.steamwar.towerrun.config.WorldConfig; import de.steamwar.towerrun.config.WorldConfig;
import de.steamwar.towerrun.state.GameStateBukkitListener; import de.steamwar.towerrun.state.GameStateBukkitListener;
import de.steamwar.towerrun.state.GameStates; import de.steamwar.towerrun.state.GameStates;
import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -44,7 +45,7 @@ public class LobbyListener extends GameStateBukkitListener {
public void onPlayerJoin(PlayerJoinEvent event) { public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (TowerRun.getTowerGenerator() != null) { 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); player.setGameMode(GameMode.SPECTATOR);
} else { } else {
player.teleport(WorldConfig.SPAWN); player.teleport(WorldConfig.SPAWN);
@ -54,6 +55,9 @@ public class LobbyListener extends GameStateBukkitListener {
@EventHandler @EventHandler
public void onPlayerMove(PlayerMoveEvent event) { public void onPlayerMove(PlayerMoveEvent event) {
if (TowerRun.getTowerGenerator() != null) {
return;
}
if(event.getTo().getY() < WorldConfig.SPAWN.getY() - 10) { if(event.getTo().getY() < WorldConfig.SPAWN.getY() - 10) {
event.getPlayer().teleport(WorldConfig.SPAWN); event.getPlayer().teleport(WorldConfig.SPAWN);
} }

Datei anzeigen

@ -38,7 +38,7 @@ public class NotLobbyListener extends GameStateBukkitListener {
public void onPlayerJoin(PlayerJoinEvent event) { public void onPlayerJoin(PlayerJoinEvent event) {
event.getPlayer().setGameMode(GameMode.SPECTATOR); event.getPlayer().setGameMode(GameMode.SPECTATOR);
if (TowerRun.getTowerGenerator() != null) { 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 { } else {
event.getPlayer().teleport(WorldConfig.SPAWN); event.getPlayer().teleport(WorldConfig.SPAWN);
} }

Datei anzeigen

@ -40,7 +40,7 @@ public abstract class WinCondition extends GameStateBukkitListener {
@Override @Override
public void enable() { public void enable() {
if (active) { if (!active) {
super.enable(); super.enable();
} }
} }