Archiviert
13
0

Revert "Add TowerGenerator"
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

This reverts commit ffcffa532d.
Dieser Commit ist enthalten in:
Chaoscaot 2023-08-19 10:28:47 +02:00
Ursprung 8818155253
Commit 5d0444db49
Signiert von: Chaoscaot
GPG-Schlüssel-ID: BDF8FADD7D5EDB7A
10 geänderte Dateien mit 8 neuen und 182 gelöschten Zeilen

Datei anzeigen

@ -21,10 +21,8 @@ package de.steamwar.towerrun;
import de.steamwar.message.Message;
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.generator.TowerGenerator;
import de.steamwar.towerrun.listener.GlobalListener;
import de.steamwar.towerrun.listener.IngameListener;
import de.steamwar.towerrun.listener.LobbyListener;
@ -36,8 +34,6 @@ import org.bukkit.plugin.java.annotation.plugin.Description;
import org.bukkit.plugin.java.annotation.plugin.Plugin;
import org.bukkit.plugin.java.annotation.plugin.author.Author;
import java.util.Optional;
@Plugin(name = "TowerRun", version = "1.0.0")
@Dependency(value = "SpigotCore")
@Author(value = "YoyoNow")
@ -51,18 +47,11 @@ public class TowerRun extends JavaPlugin {
@Getter
private static Message message;
@Getter
private static TowerGenerator towerGenerator = null;
@Override
public void onEnable() {
instance = this;
message = new Message("TowerRun", getClassLoader());
if (WorldConfig.TOWER_GENERATOR_CONFIG != null) {
towerGenerator = new TowerGenerator(WorldConfig.TOWER_GENERATOR_CONFIG);
}
new LobbyListener();
new IngameListener();
new GlobalListener();

Datei anzeigen

@ -19,7 +19,6 @@
package de.steamwar.towerrun.config;
import de.steamwar.sql.SchematicType;
import de.steamwar.towerrun.TowerRun;
import de.steamwar.towerrun.winconditions.FirstOutsideWincondition;
import de.steamwar.towerrun.winconditions.LastOutsideWincondition;
@ -54,7 +53,6 @@ public class WorldConfig {
public static final int MAP_MIN_Z;
public static final int MAP_MAX_X;
public static final int MAP_MAX_Z;
public static final TowerGeneratorConfig TOWER_GENERATOR_CONFIG;
public static final List<WinCondition> WINCONDITIONS = new ArrayList<>();
static {
@ -151,13 +149,6 @@ 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");
if (towerGeneratorSection == null) {
TOWER_GENERATOR_CONFIG = null;
} else {
TOWER_GENERATOR_CONFIG = new TowerGeneratorConfig(towerGeneratorSection);
}
}
@Getter
@ -185,19 +176,4 @@ public class WorldConfig {
&& vector.getZ() >= min.getZ() && vector.getZ() <= max.getZ();
}
}
@Getter
public static final class TowerGeneratorConfig {
public final int x;
public final int y;
public final int z;
public final SchematicType schematicType;
public TowerGeneratorConfig(ConfigurationSection section) {
x = section.getInt("x");
y = section.getInt("y");
z = section.getInt("z");
schematicType = SchematicType.fromDB(section.getString("schematicType"));
}
}
}

Datei anzeigen

@ -47,7 +47,7 @@ public class LobbyCountdown extends Countdown {
@Override
void timerEnd() {
TowerRunGame.prepareTower();
TowerRunGame.start();
}
@Override

Datei anzeigen

@ -48,22 +48,8 @@ public class TowerRunGame {
return PLAYERS_ALIVE.contains(player);
}
public static void prepareTower() {
public static void start() {
if (GameState.getCurrentState() == GameStates.LOBBY) {
GameState.nextState();
if (TowerRun.getTowerGenerator() == null) {
start();
return;
}
TowerRun.getTowerGenerator().generate(TowerRunGame::start);
} else {
throw new IllegalStateException("Game is already running!");
}
}
private static void start() {
if (GameState.getCurrentState() == GameStates.GENERATING_TOWER) {
PLAYERS_ALIVE.addAll(TowerRunPlayer.getAll());
PLAYERS_ALIVE.forEach(TowerRunPlayer::reset);
GameState.nextState();

Datei anzeigen

@ -19,7 +19,6 @@
package de.steamwar.towerrun.game;
import de.steamwar.towerrun.TowerRun;
import de.steamwar.towerrun.config.WorldConfig;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
@ -44,11 +43,7 @@ public record TowerRunPlayer(Player player) {
}
public void reset() {
if (TowerRun.getTowerGenerator() != null) {
player.teleport(WorldConfig.SPAWN.add(0, TowerRun.getTowerGenerator().getHeight(), 0));
} else {
player.teleport(WorldConfig.SPAWN);
}
player.teleport(WorldConfig.SPAWN);
player.setVelocity(new Vector(0, 0, 0));
}

Datei anzeigen

@ -1,104 +0,0 @@
package de.steamwar.towerrun.generator;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.session.ClipboardHolder;
import de.steamwar.sql.SchematicData;
import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SchematicType;
import de.steamwar.towerrun.TowerRun;
import de.steamwar.towerrun.config.WorldConfig;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitRunnable;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;
import java.util.Objects;
import java.util.Random;
public class TowerGenerator {
private Random random = new Random();
private int x;
private int y;
private int z;
private List<SchematicNode> ALL_SCHEMATICS;
private Clipboard roof;
@Getter
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.schematic");
if (!file.exists()) {
Bukkit.shutdown();
return;
}
roof = loadSchematic(file);
this.x = x;
this.y = y;
this.z = z;
ALL_SCHEMATICS = SchematicNode.getAllSchematicsOfType(schematicType);
}
private Clipboard loadSchematic(File file) {
Clipboard clipboard;
try (ClipboardReader reader = Objects.requireNonNull(ClipboardFormats.findByFile(file)).getReader(new FileInputStream(file))) {
clipboard = reader.read();
} catch (NullPointerException | IOException e) {
Bukkit.shutdown();
throw new SecurityException("TowerRun schematic not found", e);
}
return clipboard;
}
public void generate(Runnable finishRunnable) {
new BukkitRunnable() {
int height = random.nextInt(50) + 200;
int y = TowerGenerator.this.y;
{
TowerGenerator.this.height = height;
}
@Override
public void run() {
if (height > 0) {
SchematicNode schematicNode = ALL_SCHEMATICS.get(random.nextInt(ALL_SCHEMATICS.size()));
SchematicData schematicData = new SchematicData(schematicNode);
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());
}
y += clipboard.getDimensions().getY();
height -= clipboard.getDimensions().getY();
} catch (IOException e) {
ALL_SCHEMATICS.remove(schematicNode);
}
} else {
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());
}
finishRunnable.run();
}
}
}.runTaskTimer(TowerRun.getInstance(), 0, 1);
}
}

Datei anzeigen

@ -112,10 +112,6 @@ 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));
} else {
event.setRespawnLocation(WorldConfig.SPAWN);
}
event.setRespawnLocation(WorldConfig.SPAWN);
}
}

Datei anzeigen

@ -19,7 +19,6 @@
package de.steamwar.towerrun.listener;
import de.steamwar.towerrun.TowerRun;
import de.steamwar.towerrun.config.WorldConfig;
import de.steamwar.towerrun.state.GameStateBukkitListener;
import de.steamwar.towerrun.state.GameStates;
@ -43,13 +42,8 @@ public class LobbyListener extends GameStateBukkitListener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
if (TowerRun.getTowerGenerator() != null) {
player.teleport(WorldConfig.SPAWN.add(0, TowerRun.getTowerGenerator().getHeight(), 0));
player.setGameMode(GameMode.SPECTATOR);
} else {
player.teleport(WorldConfig.SPAWN);
player.setGameMode(GameMode.SURVIVAL);
}
player.teleport(WorldConfig.SPAWN);
player.setGameMode(GameMode.SURVIVAL);
}
@EventHandler

Datei anzeigen

@ -19,7 +19,6 @@
package de.steamwar.towerrun.listener;
import de.steamwar.towerrun.TowerRun;
import de.steamwar.towerrun.config.WorldConfig;
import de.steamwar.towerrun.state.GameStateBukkitListener;
import de.steamwar.towerrun.state.GameStates;
@ -37,10 +36,6 @@ public class NotLobbyListener extends GameStateBukkitListener {
@EventHandler
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));
} else {
event.getPlayer().teleport(WorldConfig.SPAWN);
}
event.getPlayer().teleport(WorldConfig.SPAWN);
}
}

Datei anzeigen

@ -27,8 +27,7 @@ import lombok.Getter;
public enum GameStates {
ENDING(null),
INGAME(ENDING),
GENERATING_TOWER(INGAME),
LOBBY(GENERATING_TOWER);
LOBBY(INGAME);
private final GameStates nextState;
}