From 394c0d5d43c5bf7eb40056c3dd49fa6e48009e7b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 18 Aug 2023 18:16:27 +0200 Subject: [PATCH 01/13] Add TowerGenerator (cherry picked from commit ffcffa532d010c1197cd735bae809ba14183ef2b) --- src/de/steamwar/towerrun/TowerRun.java | 11 ++ .../steamwar/towerrun/config/WorldConfig.java | 24 ++++ .../towerrun/countdowns/LobbyCountdown.java | 2 +- .../steamwar/towerrun/game/TowerRunGame.java | 16 ++- .../towerrun/game/TowerRunPlayer.java | 7 +- .../towerrun/generator/TowerGenerator.java | 104 ++++++++++++++++++ .../towerrun/listener/IngameListener.java | 6 +- .../towerrun/listener/LobbyListener.java | 10 +- .../towerrun/listener/NotLobbyListener.java | 7 +- .../steamwar/towerrun/state/GameStates.java | 3 +- 10 files changed, 182 insertions(+), 8 deletions(-) create mode 100644 src/de/steamwar/towerrun/generator/TowerGenerator.java diff --git a/src/de/steamwar/towerrun/TowerRun.java b/src/de/steamwar/towerrun/TowerRun.java index 28545d2..4b1f47d 100644 --- a/src/de/steamwar/towerrun/TowerRun.java +++ b/src/de/steamwar/towerrun/TowerRun.java @@ -21,8 +21,10 @@ 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; @@ -34,6 +36,8 @@ 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") @@ -47,11 +51,18 @@ 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(); diff --git a/src/de/steamwar/towerrun/config/WorldConfig.java b/src/de/steamwar/towerrun/config/WorldConfig.java index 0a242af..c888197 100644 --- a/src/de/steamwar/towerrun/config/WorldConfig.java +++ b/src/de/steamwar/towerrun/config/WorldConfig.java @@ -19,6 +19,7 @@ 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; @@ -53,6 +54,7 @@ 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 WINCONDITIONS = new ArrayList<>(); static { @@ -149,6 +151,13 @@ 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 @@ -176,4 +185,19 @@ 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")); + } + } } diff --git a/src/de/steamwar/towerrun/countdowns/LobbyCountdown.java b/src/de/steamwar/towerrun/countdowns/LobbyCountdown.java index 43093b7..35a1794 100644 --- a/src/de/steamwar/towerrun/countdowns/LobbyCountdown.java +++ b/src/de/steamwar/towerrun/countdowns/LobbyCountdown.java @@ -47,7 +47,7 @@ public class LobbyCountdown extends Countdown { @Override void timerEnd() { - TowerRunGame.start(); + TowerRunGame.prepareTower(); } @Override diff --git a/src/de/steamwar/towerrun/game/TowerRunGame.java b/src/de/steamwar/towerrun/game/TowerRunGame.java index 0bc5db1..d0b14d6 100644 --- a/src/de/steamwar/towerrun/game/TowerRunGame.java +++ b/src/de/steamwar/towerrun/game/TowerRunGame.java @@ -48,8 +48,22 @@ public class TowerRunGame { return PLAYERS_ALIVE.contains(player); } - public static void start() { + public static void prepareTower() { 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(); diff --git a/src/de/steamwar/towerrun/game/TowerRunPlayer.java b/src/de/steamwar/towerrun/game/TowerRunPlayer.java index 9aa4629..015073b 100644 --- a/src/de/steamwar/towerrun/game/TowerRunPlayer.java +++ b/src/de/steamwar/towerrun/game/TowerRunPlayer.java @@ -19,6 +19,7 @@ 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; @@ -43,7 +44,11 @@ public record TowerRunPlayer(Player player) { } public void reset() { - player.teleport(WorldConfig.SPAWN); + if (TowerRun.getTowerGenerator() != null) { + player.teleport(WorldConfig.SPAWN.add(0, TowerRun.getTowerGenerator().getHeight(), 0)); + } else { + player.teleport(WorldConfig.SPAWN); + } player.setVelocity(new Vector(0, 0, 0)); } diff --git a/src/de/steamwar/towerrun/generator/TowerGenerator.java b/src/de/steamwar/towerrun/generator/TowerGenerator.java new file mode 100644 index 0000000..e1493df --- /dev/null +++ b/src/de/steamwar/towerrun/generator/TowerGenerator.java @@ -0,0 +1,104 @@ +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 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); + } +} diff --git a/src/de/steamwar/towerrun/listener/IngameListener.java b/src/de/steamwar/towerrun/listener/IngameListener.java index 62b1295..7ba25dd 100644 --- a/src/de/steamwar/towerrun/listener/IngameListener.java +++ b/src/de/steamwar/towerrun/listener/IngameListener.java @@ -112,6 +112,10 @@ public class IngameListener extends GameStateBukkitListener { @EventHandler public void onPlayerRespawn(PlayerRespawnEvent event) { - event.setRespawnLocation(WorldConfig.SPAWN); + if (TowerRun.getTowerGenerator() != null) { + event.setRespawnLocation(WorldConfig.SPAWN.add(0, TowerRun.getTowerGenerator().getHeight(), 0)); + } else { + event.setRespawnLocation(WorldConfig.SPAWN); + } } } diff --git a/src/de/steamwar/towerrun/listener/LobbyListener.java b/src/de/steamwar/towerrun/listener/LobbyListener.java index 470b198..b7542c1 100644 --- a/src/de/steamwar/towerrun/listener/LobbyListener.java +++ b/src/de/steamwar/towerrun/listener/LobbyListener.java @@ -19,6 +19,7 @@ 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; @@ -42,8 +43,13 @@ public class LobbyListener extends GameStateBukkitListener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); - player.teleport(WorldConfig.SPAWN); - player.setGameMode(GameMode.SURVIVAL); + 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); + } } @EventHandler diff --git a/src/de/steamwar/towerrun/listener/NotLobbyListener.java b/src/de/steamwar/towerrun/listener/NotLobbyListener.java index 20078f9..1784e47 100644 --- a/src/de/steamwar/towerrun/listener/NotLobbyListener.java +++ b/src/de/steamwar/towerrun/listener/NotLobbyListener.java @@ -19,6 +19,7 @@ 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; @@ -36,6 +37,10 @@ public class NotLobbyListener extends GameStateBukkitListener { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { event.getPlayer().setGameMode(GameMode.SPECTATOR); - event.getPlayer().teleport(WorldConfig.SPAWN); + if (TowerRun.getTowerGenerator() != null) { + event.getPlayer().teleport(WorldConfig.SPAWN.add(0, TowerRun.getTowerGenerator().getHeight(), 0)); + } else { + event.getPlayer().teleport(WorldConfig.SPAWN); + } } } diff --git a/src/de/steamwar/towerrun/state/GameStates.java b/src/de/steamwar/towerrun/state/GameStates.java index 3c838a3..347e981 100644 --- a/src/de/steamwar/towerrun/state/GameStates.java +++ b/src/de/steamwar/towerrun/state/GameStates.java @@ -27,7 +27,8 @@ import lombok.Getter; public enum GameStates { ENDING(null), INGAME(ENDING), - LOBBY(INGAME); + GENERATING_TOWER(INGAME), + LOBBY(GENERATING_TOWER); private final GameStates nextState; } -- 2.39.5 From d4c6e2a5194fd2f49dbcdb587de1e801960baf70 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 18 Aug 2023 18:23:44 +0200 Subject: [PATCH 02/13] Add steamtower.yml (cherry picked from commit 2547bee1746c2750e00005464d2bd19d7bb29426) --- configs/steamtower.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 configs/steamtower.yml diff --git a/configs/steamtower.yml b/configs/steamtower.yml new file mode 100644 index 0000000..e25a261 --- /dev/null +++ b/configs/steamtower.yml @@ -0,0 +1,33 @@ +tower: + regions: + 1: + minX: 0 + maxX: 0 + minZ: 69 + maxZ: 79 + escapeHeight: 1 + spawn: + x: 66 + y: 23 + z: 71 + yaw: 180.0 + pitch: 0.0 + doors: [] + keys: [] + lavaY: 220 + laveSpace: 7 + +towerGenerator: + x: 0 + y: 12 + z: 0 + schematicType: steamtower + +minX: -20 +maxX: 89 +minZ: -20 +maxZ: 99 + +winconditions: + - LAST_REMAINING + - LAST_OUTSIDE \ No newline at end of file -- 2.39.5 From 5898454089c20b1d9d9b6593d9cd7c78dd55cee2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 18 Aug 2023 18:28:53 +0200 Subject: [PATCH 03/13] Fix stuff (cherry picked from commit 2727a827776efe255800a6deea2d2d86d2d7ada7) --- src/de/steamwar/towerrun/generator/TowerGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/towerrun/generator/TowerGenerator.java b/src/de/steamwar/towerrun/generator/TowerGenerator.java index e1493df..f61a2fe 100644 --- a/src/de/steamwar/towerrun/generator/TowerGenerator.java +++ b/src/de/steamwar/towerrun/generator/TowerGenerator.java @@ -42,7 +42,7 @@ public class TowerGenerator { } public TowerGenerator(int x, int y, int z, SchematicType schematicType) { - File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "Roof.schematic"); + File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "Roof.schem"); if (!file.exists()) { Bukkit.shutdown(); return; -- 2.39.5 From fecd771a8bcf3ea3cc7fb5e9c31ddd28caac06b1 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 18 Aug 2023 18:47:48 +0200 Subject: [PATCH 04/13] Fix stuff (cherry picked from commit 67376fc5a447911c5ab8a873c64899f27fc89384) --- configs/steamtower.yml | 2 +- .../steamwar/towerrun/config/WorldConfig.java | 34 ++++++++++++------- .../steamwar/towerrun/game/TowerRunGame.java | 8 +++-- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/configs/steamtower.yml b/configs/steamtower.yml index e25a261..de69118 100644 --- a/configs/steamtower.yml +++ b/configs/steamtower.yml @@ -14,7 +14,7 @@ tower: pitch: 0.0 doors: [] keys: [] - lavaY: 220 + lavaY: 78 laveSpace: 7 towerGenerator: diff --git a/src/de/steamwar/towerrun/config/WorldConfig.java b/src/de/steamwar/towerrun/config/WorldConfig.java index c888197..9b48e76 100644 --- a/src/de/steamwar/towerrun/config/WorldConfig.java +++ b/src/de/steamwar/towerrun/config/WorldConfig.java @@ -125,20 +125,30 @@ public class WorldConfig { ESCAPE_HEIGHT = tower.getInt("escapeHeight"); SPAWN = parseLocation(tower.getConfigurationSection("spawn")); - List doors = tower.getConfigurationSection("doors").getKeys(false).stream() - .map(tower.getConfigurationSection("doors")::getConfigurationSection) - .toList(); - DOORS = new Location[doors.size()]; - for (int i = 0; i < doors.size(); i++) { - DOORS[i] = parseLocation(doors.get(i)); + ConfigurationSection doorSection = tower.getConfigurationSection("doors"); + if (doorSection != null) { + List doors = doorSection.getKeys(false).stream() + .map(tower.getConfigurationSection("doors")::getConfigurationSection) + .toList(); + DOORS = new Location[doors.size()]; + for (int i = 0; i < doors.size(); i++) { + DOORS[i] = parseLocation(doors.get(i)); + } + } else { + DOORS = new Location[0]; } - List keys = tower.getConfigurationSection("keys").getKeys(false).stream() - .map(tower.getConfigurationSection("keys")::getConfigurationSection) - .toList(); - KEYS = new Location[keys.size()]; - for (int i = 0; i < keys.size(); i++) { - KEYS[i] = parseLocation(keys.get(i)); + ConfigurationSection keysSection = tower.getConfigurationSection("keys"); + if (keysSection != null) { + List keys = keysSection.getKeys(false).stream() + .map(tower.getConfigurationSection("keys")::getConfigurationSection) + .toList(); + KEYS = new Location[keys.size()]; + for (int i = 0; i < keys.size(); i++) { + KEYS[i] = parseLocation(keys.get(i)); + } + } else { + KEYS = new Location[0]; } LAVA_Y = tower.getInt("lavaY"); diff --git a/src/de/steamwar/towerrun/game/TowerRunGame.java b/src/de/steamwar/towerrun/game/TowerRunGame.java index d0b14d6..ec24426 100644 --- a/src/de/steamwar/towerrun/game/TowerRunGame.java +++ b/src/de/steamwar/towerrun/game/TowerRunGame.java @@ -84,8 +84,12 @@ public class TowerRunGame { for (int z = WorldConfig.MIN_TOWER.getBlockZ(); z < WorldConfig.MAX_TOWER.getBlockZ(); z += WorldConfig.LAVE_SPACE) { Vector pos = new Vector(x, 0, z); if (Arrays.stream(WorldConfig.REGIONS).anyMatch(region -> region.contains(pos))) { - WorldConfig.MIN_TOWER.getWorld().getBlockAt(x, WorldConfig.LAVA_Y, z).setType(Material.LAVA, true); - WorldConfig.MIN_TOWER.getWorld().getBlockAt(x, WorldConfig.LAVA_Y - 1, z).setType(Material.BEDROCK, true); + int offset = WorldConfig.LAVA_Y; + if (TowerRun.getTowerGenerator() != null) { + offset += TowerRun.getTowerGenerator().getHeight(); + } + WorldConfig.MIN_TOWER.getWorld().getBlockAt(x, offset, z).setType(Material.LAVA, true); + WorldConfig.MIN_TOWER.getWorld().getBlockAt(x, offset - 1, z).setType(Material.BEDROCK, true); } } } -- 2.39.5 From 0e9ba50cde8ccae55d0682243b625bee51248430 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 19 Aug 2023 00:47:47 +0200 Subject: [PATCH 05/13] Fix stuff (cherry picked from commit 65f5e645050c7d414c68240134f4456523ac8676) --- configs/steamtower.yml | 40 +++++++++++++---- src/de/steamwar/towerrun/TowerRun.java | 3 ++ .../steamwar/towerrun/config/WorldConfig.java | 37 +++++++++++++++- .../towerrun/countdowns/LobbyCountdown.java | 1 + .../steamwar/towerrun/game/TowerRunGame.java | 11 ++++- .../towerrun/game/TowerRunPlayer.java | 2 +- .../towerrun/generator/TowerGenerator.java | 43 ++++++++++++------- .../towerrun/listener/IngameListener.java | 2 +- .../towerrun/listener/LobbyListener.java | 6 ++- .../towerrun/listener/NotLobbyListener.java | 2 +- .../towerrun/winconditions/WinCondition.java | 2 +- 11 files changed, 117 insertions(+), 32 deletions(-) diff --git a/configs/steamtower.yml b/configs/steamtower.yml index de69118..397307f 100644 --- a/configs/steamtower.yml +++ b/configs/steamtower.yml @@ -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 diff --git a/src/de/steamwar/towerrun/TowerRun.java b/src/de/steamwar/towerrun/TowerRun.java index 4b1f47d..e917740 100644 --- a/src/de/steamwar/towerrun/TowerRun.java +++ b/src/de/steamwar/towerrun/TowerRun.java @@ -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(); } } diff --git a/src/de/steamwar/towerrun/config/WorldConfig.java b/src/de/steamwar/towerrun/config/WorldConfig.java index 9b48e76..43b08f7 100644 --- a/src/de/steamwar/towerrun/config/WorldConfig.java +++ b/src/de/steamwar/towerrun/config/WorldConfig.java @@ -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 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")); } } } diff --git a/src/de/steamwar/towerrun/countdowns/LobbyCountdown.java b/src/de/steamwar/towerrun/countdowns/LobbyCountdown.java index 35a1794..df8a5a0 100644 --- a/src/de/steamwar/towerrun/countdowns/LobbyCountdown.java +++ b/src/de/steamwar/towerrun/countdowns/LobbyCountdown.java @@ -48,6 +48,7 @@ public class LobbyCountdown extends Countdown { @Override void timerEnd() { TowerRunGame.prepareTower(); + override = false; } @Override diff --git a/src/de/steamwar/towerrun/game/TowerRunGame.java b/src/de/steamwar/towerrun/game/TowerRunGame.java index ec24426..477d4e1 100644 --- a/src/de/steamwar/towerrun/game/TowerRunGame.java +++ b/src/de/steamwar/towerrun/game/TowerRunGame.java @@ -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 -> { - player.setGameMode(GameMode.SURVIVAL); + if (TowerRun.getTowerGenerator() != null) { + player.setGameMode(GameMode.SPECTATOR); + } else { + player.setGameMode(GameMode.SURVIVAL); + } player.teleport(WorldConfig.SPAWN); }); } diff --git a/src/de/steamwar/towerrun/game/TowerRunPlayer.java b/src/de/steamwar/towerrun/game/TowerRunPlayer.java index 015073b..b2ac89d 100644 --- a/src/de/steamwar/towerrun/game/TowerRunPlayer.java +++ b/src/de/steamwar/towerrun/game/TowerRunPlayer.java @@ -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); } diff --git a/src/de/steamwar/towerrun/generator/TowerGenerator.java b/src/de/steamwar/towerrun/generator/TowerGenerator.java index f61a2fe..5df358f 100644 --- a/src/de/steamwar/towerrun/generator/TowerGenerator.java +++ b/src/de/steamwar/towerrun/generator/TowerGenerator.java @@ -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 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); } } diff --git a/src/de/steamwar/towerrun/listener/IngameListener.java b/src/de/steamwar/towerrun/listener/IngameListener.java index 7ba25dd..e084d45 100644 --- a/src/de/steamwar/towerrun/listener/IngameListener.java +++ b/src/de/steamwar/towerrun/listener/IngameListener.java @@ -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); } diff --git a/src/de/steamwar/towerrun/listener/LobbyListener.java b/src/de/steamwar/towerrun/listener/LobbyListener.java index b7542c1..d579ab3 100644 --- a/src/de/steamwar/towerrun/listener/LobbyListener.java +++ b/src/de/steamwar/towerrun/listener/LobbyListener.java @@ -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); } diff --git a/src/de/steamwar/towerrun/listener/NotLobbyListener.java b/src/de/steamwar/towerrun/listener/NotLobbyListener.java index 1784e47..4dacaf2 100644 --- a/src/de/steamwar/towerrun/listener/NotLobbyListener.java +++ b/src/de/steamwar/towerrun/listener/NotLobbyListener.java @@ -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); } diff --git a/src/de/steamwar/towerrun/winconditions/WinCondition.java b/src/de/steamwar/towerrun/winconditions/WinCondition.java index 4a736dd..355f953 100644 --- a/src/de/steamwar/towerrun/winconditions/WinCondition.java +++ b/src/de/steamwar/towerrun/winconditions/WinCondition.java @@ -40,7 +40,7 @@ public abstract class WinCondition extends GameStateBukkitListener { @Override public void enable() { - if (active) { + if (!active) { super.enable(); } } -- 2.39.5 From 24a5c3e99596fbd17e054b6d6ee569e732da2abd Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 19 Aug 2023 12:30:57 +0200 Subject: [PATCH 06/13] Add WorldConfig.MELTING_TIMES --- configs/steamtower.yml | 51 ++++++++++++-- src/de/steamwar/towerrun/TowerRun.java | 2 - .../steamwar/towerrun/config/WorldConfig.java | 23 +++++-- .../towerrun/countdowns/LobbyCountdown.java | 2 +- .../steamwar/towerrun/game/TowerRunGame.java | 6 +- .../towerrun/game/TowerRunPlayer.java | 2 +- .../towerrun/generator/TowerGenerator.java | 27 +++++--- .../towerrun/listener/IngameListener.java | 67 ++++++++++++++++++- .../towerrun/listener/LobbyListener.java | 3 +- .../towerrun/listener/NotLobbyListener.java | 2 +- 10 files changed, 151 insertions(+), 34 deletions(-) diff --git a/configs/steamtower.yml b/configs/steamtower.yml index 397307f..1f820a1 100644 --- a/configs/steamtower.yml +++ b/configs/steamtower.yml @@ -16,6 +16,49 @@ tower: keys: [] lavaY: 76 laveSpace: 9 + meltingBlocks: + SMOOTH_STONE: 120 + SMOOTH_STONE_SLAB: 60 + ANDESITE: 120 + JUKEBOX: 10 + IRON_BLOCK: 240 + END_STONE: 240 + REDSTONE_LAMP: 30 + GLASS: 30 + GLASS_PANE: 3 + TINTED_GLASS: 30 + WHITE_STAINED_GLASS: 30 + WHITE_STAINED_GLASS_PANE: 3 + ORANGE_STAINED_GLASS: 30 + ORANGE_STAINED_GLASS_PANE: 3 + MAGENTA_STAINED_GLASS: 30 + MAGENTA_STAINED_GLASS_PANE: 3 + LIGHT_BLUE_STAINED_GLASS: 30 + LIGHT_BLUE_STAINED_GLASS_PANE: 3 + YELLOW_STAINED_GLASS: 30 + YELLOW_STAINED_GLASS_PANE: 3 + LIME_STAINED_GLASS: 30 + LIME_STAINED_GLASS_PANE: 3 + PINK_STAINED_GLASS: 30 + PINK_STAINED_GLASS_PANE: 3 + GRAY_STAINED_GLASS: 30 + GRAY_STAINED_GLASS_PANE: 3 + LIGHT_GRAY_STAINED_GLASS: 30 + LIGHT_GRAY_STAINED_GLASS_PANE: 3 + CYAN_STAINED_GLASS: 30 + CYAN_STAINED_GLASS_PANE: 3 + PURPLE_STAINED_GLASS: 30 + PURPLE_STAINED_GLASS_PANE: 3 + BLUE_STAINED_GLASS: 30 + BLUE_STAINED_GLASS_PANE: 3 + BROWN_STAINED_GLASS: 30 + BROWN_STAINED_GLASS_PANE: 3 + GREEN_STAINED_GLASS: 30 + GREEN_STAINED_GLASS_PANE: 3 + RED_STAINED_GLASS: 30 + RED_STAINED_GLASS_PANE: 3 + BLACK_STAINED_GLASS: 30 + BLACK_STAINED_GLASS_PANE: 3 towerGenerator: x: 0 @@ -45,10 +88,10 @@ towerGenerator: percentage: 1.0 material: MANGROVE_ROOTS -minX: -40 -maxX: 109 -minZ: -40 -maxZ: 119 +minX: -28 +maxX: 98 +minZ: -27 +maxZ: 107 winconditions: - LAST_REMAINING diff --git a/src/de/steamwar/towerrun/TowerRun.java b/src/de/steamwar/towerrun/TowerRun.java index 6d6a214..f72eade 100644 --- a/src/de/steamwar/towerrun/TowerRun.java +++ b/src/de/steamwar/towerrun/TowerRun.java @@ -38,8 +38,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("SpigotCore") @Author("YoyoNow") diff --git a/src/de/steamwar/towerrun/config/WorldConfig.java b/src/de/steamwar/towerrun/config/WorldConfig.java index 43b08f7..f26e12e 100644 --- a/src/de/steamwar/towerrun/config/WorldConfig.java +++ b/src/de/steamwar/towerrun/config/WorldConfig.java @@ -35,8 +35,7 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.util.Vector; import java.io.File; -import java.util.ArrayList; -import java.util.List; +import java.util.*; @UtilityClass public class WorldConfig { @@ -55,6 +54,7 @@ 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 Map MELTING_TIMES; public static final TowerGeneratorConfig TOWER_GENERATOR_CONFIG; public static final List WINCONDITIONS = new ArrayList<>(); @@ -160,6 +160,17 @@ public class WorldConfig { MAP_MAX_X = config.getInt("maxX"); MAP_MAX_Z = config.getInt("maxZ"); + ConfigurationSection meltingBlocksSection = tower.getConfigurationSection("meltingBlocks"); + if (meltingBlocksSection != null) { + Map meltingTimes = new HashMap<>(); + meltingBlocksSection.getKeys(false).forEach(s -> { + meltingTimes.put(Material.valueOf(s), meltingBlocksSection.getInt(s)); + }); + MELTING_TIMES = Collections.unmodifiableMap(meltingTimes); + } else { + MELTING_TIMES = Collections.emptyMap(); + } + ACTIVE_WINCONDITIONS = config.getStringList("winconditions"); WINCONDITIONS.stream().filter(winCondition -> ACTIVE_WINCONDITIONS.contains(winCondition.getName())).forEach(winCondition -> winCondition.setActive(true)); @@ -203,7 +214,7 @@ public class WorldConfig { public final int y; public final int z; public final SchematicType schematicType; - public final TowerGeneratorFillRegion[] FILL_REGIONS; + public final TowerGeneratorFillRegion[] fillRegions; public TowerGeneratorConfig(ConfigurationSection section) { x = section.getInt("x"); @@ -217,12 +228,12 @@ public class WorldConfig { .map(fillRegionsSection::getConfigurationSection) .toList(); - FILL_REGIONS = new TowerGeneratorFillRegion[fillRegions.size()]; + this.fillRegions = new TowerGeneratorFillRegion[fillRegions.size()]; for (int i = 0; i < fillRegions.size(); i++) { - FILL_REGIONS[i] = new TowerGeneratorFillRegion(fillRegions.get(i)); + this.fillRegions[i] = new TowerGeneratorFillRegion(fillRegions.get(i)); } } else { - FILL_REGIONS = new TowerGeneratorFillRegion[0]; + fillRegions = new TowerGeneratorFillRegion[0]; } } } diff --git a/src/de/steamwar/towerrun/countdowns/LobbyCountdown.java b/src/de/steamwar/towerrun/countdowns/LobbyCountdown.java index df8a5a0..40808f1 100644 --- a/src/de/steamwar/towerrun/countdowns/LobbyCountdown.java +++ b/src/de/steamwar/towerrun/countdowns/LobbyCountdown.java @@ -47,7 +47,7 @@ public class LobbyCountdown extends Countdown { @Override void timerEnd() { - TowerRunGame.prepareTower(); + TowerRunGame.prepareTowerOrStart(); override = false; } diff --git a/src/de/steamwar/towerrun/game/TowerRunGame.java b/src/de/steamwar/towerrun/game/TowerRunGame.java index 477d4e1..04824a8 100644 --- a/src/de/steamwar/towerrun/game/TowerRunGame.java +++ b/src/de/steamwar/towerrun/game/TowerRunGame.java @@ -48,7 +48,7 @@ public class TowerRunGame { return PLAYERS_ALIVE.contains(player); } - public static void prepareTower() { + public static void prepareTowerOrStart() { if (GameState.getCurrentState() == GameStates.LOBBY) { GameState.nextState(); if (TowerRun.getTowerGenerator() == null) { @@ -56,13 +56,13 @@ public class TowerRunGame { return; } - TowerRun.getTowerGenerator().generate(TowerRunGame::start); + TowerRun.getTowerGenerator().generate(); } else { throw new IllegalStateException("Game is already running!"); } } - private static void start() { + public static void start() { if (GameState.getCurrentState() == GameStates.GENERATING_TOWER) { PLAYERS_ALIVE.addAll(TowerRunPlayer.getAll()); PLAYERS_ALIVE.forEach(p -> { diff --git a/src/de/steamwar/towerrun/game/TowerRunPlayer.java b/src/de/steamwar/towerrun/game/TowerRunPlayer.java index b2ac89d..b60ddb7 100644 --- a/src/de/steamwar/towerrun/game/TowerRunPlayer.java +++ b/src/de/steamwar/towerrun/game/TowerRunPlayer.java @@ -45,7 +45,7 @@ public record TowerRunPlayer(Player player) { public void reset() { if (TowerRun.getTowerGenerator() != null) { - player.teleport(WorldConfig.SPAWN.clone().add(0, TowerRun.getTowerGenerator().getHeight(), 0)); + player.teleport(TowerRun.getTowerGenerator().getSpawn()); } else { player.teleport(WorldConfig.SPAWN); } diff --git a/src/de/steamwar/towerrun/generator/TowerGenerator.java b/src/de/steamwar/towerrun/generator/TowerGenerator.java index 5df358f..07fcc58 100644 --- a/src/de/steamwar/towerrun/generator/TowerGenerator.java +++ b/src/de/steamwar/towerrun/generator/TowerGenerator.java @@ -11,11 +11,12 @@ 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 de.steamwar.towerrun.game.TowerRunGame; import lombok.Getter; import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.scheduler.BukkitRunnable; @@ -28,24 +29,27 @@ import java.util.Random; public class TowerGenerator { - private Random random = new Random(); - private WorldConfig.TowerGeneratorConfig config; - private List ALL_SCHEMATICS; + private static final Random random = new Random(); + private final WorldConfig.TowerGeneratorConfig config; + private List allSchematics; private Clipboard roof; @Getter private int height; + @Getter + private Location spawn; + public TowerGenerator(WorldConfig.TowerGeneratorConfig config) { File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "Roof.schem"); if (!file.exists()) { Bukkit.shutdown(); - return; + throw new SecurityException("TowerRun schematic not found"); } roof = loadSchematic(file); this.config = config; - ALL_SCHEMATICS = SchematicNode.getAllSchematicsOfType(config.schematicType); + allSchematics = SchematicNode.getAllSchematicsOfType(config.schematicType); } private Clipboard loadSchematic(File file) { @@ -59,7 +63,7 @@ public class TowerGenerator { return clipboard; } - public void generate(Runnable finishRunnable) { + public void generate() { new BukkitRunnable() { int height = random.nextInt(50) + 200; int y = TowerGenerator.this.config.y; @@ -71,7 +75,7 @@ public class TowerGenerator { @Override public void run() { if (height > 0) { - SchematicNode schematicNode = ALL_SCHEMATICS.get(random.nextInt(ALL_SCHEMATICS.size())); + SchematicNode schematicNode = allSchematics.get(random.nextInt(allSchematics.size())); SchematicData schematicData = new SchematicData(schematicNode); int currentY; try { @@ -84,11 +88,12 @@ public class TowerGenerator { y += clipboard.getDimensions().getY(); height -= clipboard.getDimensions().getY(); } catch (IOException e) { - ALL_SCHEMATICS.remove(schematicNode); + allSchematics.remove(schematicNode); return; } + spawn = WorldConfig.SPAWN.clone().add(0, y, 0); - for (WorldConfig.TowerGeneratorFillRegion fillRegion : config.FILL_REGIONS) { + for (WorldConfig.TowerGeneratorFillRegion fillRegion : config.fillRegions) { 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++) { @@ -109,7 +114,7 @@ public class TowerGenerator { ClipboardHolder ch = new ClipboardHolder(roof); Operations.completeBlindly(ch.createPaste(e).to(BlockVector3.at(config.x, y, config.z)).build()); } - finishRunnable.run(); + TowerRunGame.start(); } } }.runTaskTimer(TowerRun.getInstance(), 0, 10); diff --git a/src/de/steamwar/towerrun/listener/IngameListener.java b/src/de/steamwar/towerrun/listener/IngameListener.java index e084d45..5c56088 100644 --- a/src/de/steamwar/towerrun/listener/IngameListener.java +++ b/src/de/steamwar/towerrun/listener/IngameListener.java @@ -26,30 +26,69 @@ 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.Material; import org.bukkit.Sound; +import org.bukkit.block.Block; import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.scheduler.BukkitRunnable; -import java.util.Arrays; -import java.util.EnumSet; +import java.util.*; public class IngameListener extends GameStateBukkitListener { + + private int time = 0; + private Map> blocksToMelt = new HashMap<>(); + private BukkitRunnable runnable; + public IngameListener() { super(EnumSet.of(GameStates.INGAME)); } + @Override + public void enable() { + super.enable(); + runnable = new BukkitRunnable() { + @Override + public void run() { + List blocks = blocksToMelt.get(time); + time++; + if (blocks == null) { + return; + } + blocks.forEach(block -> { + if (!WorldConfig.MELTING_TIMES.containsKey(block.getType())) return; + block.setType(Material.AIR); + block.getWorld().playSound(block.getLocation(), Sound.BLOCK_FIRE_EXTINGUISH, 0.1F, 1); + }); + } + }; + runnable.runTaskTimer(TowerRun.getInstance(), 0, 1); + } + + @Override + public void disable() { + super.disable(); + runnable.cancel(); + runnable = null; + blocksToMelt.clear(); + time = 0; + } + @EventHandler public void onPlayerDeath(PlayerDeathEvent event) { event.setDeathMessage(null); + event.getEntity().setGameMode(GameMode.SPECTATOR); Bukkit.getOnlinePlayers().forEach(player -> { player.sendTitle("", TowerRun.getMessage().parse("PLAYER_DIED", player, event.getEntity().getPlayer().getName()), 10, 70, 20); player.playSound(player.getLocation(), Sound.ENTITY_WITHER_DEATH, 1, 1); @@ -113,9 +152,31 @@ public class IngameListener extends GameStateBukkitListener { @EventHandler public void onPlayerRespawn(PlayerRespawnEvent event) { if (TowerRun.getTowerGenerator() != null) { - event.setRespawnLocation(WorldConfig.SPAWN.clone().add(0, TowerRun.getTowerGenerator().getHeight(), 0)); + event.setRespawnLocation(TowerRun.getTowerGenerator().getSpawn()); } else { event.setRespawnLocation(WorldConfig.SPAWN); } } + + @EventHandler + public void onBlockPhysics(BlockPhysicsEvent event) { + if (event.getSourceBlock().getType() != Material.LAVA) { + return; + } + Block block = event.getSourceBlock(); + shouldMelt(block.getRelative(0, 1, 0)); + shouldMelt(block.getRelative(0, -1, 0)); + shouldMelt(block.getRelative(1, 0, 0)); + shouldMelt(block.getRelative(-1, 0, 0)); + shouldMelt(block.getRelative(0, 0, 1)); + shouldMelt(block.getRelative(0, 0, -1)); + } + + private void shouldMelt(Block block) { + int meltingTime = WorldConfig.MELTING_TIMES.getOrDefault(block.getType(), -1); + if (meltingTime == -1) { + return; + } + blocksToMelt.computeIfAbsent(time + meltingTime * 20, integer -> new ArrayList<>()).add(block); + } } diff --git a/src/de/steamwar/towerrun/listener/LobbyListener.java b/src/de/steamwar/towerrun/listener/LobbyListener.java index d579ab3..5c937ed 100644 --- a/src/de/steamwar/towerrun/listener/LobbyListener.java +++ b/src/de/steamwar/towerrun/listener/LobbyListener.java @@ -23,7 +23,6 @@ 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; @@ -45,7 +44,7 @@ public class LobbyListener extends GameStateBukkitListener { public void onPlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); if (TowerRun.getTowerGenerator() != null) { - player.teleport(WorldConfig.SPAWN.clone().add(0, TowerRun.getTowerGenerator().getHeight(), 0)); + player.teleport(TowerRun.getTowerGenerator().getSpawn()); player.setGameMode(GameMode.SPECTATOR); } else { player.teleport(WorldConfig.SPAWN); diff --git a/src/de/steamwar/towerrun/listener/NotLobbyListener.java b/src/de/steamwar/towerrun/listener/NotLobbyListener.java index 4dacaf2..4d3525e 100644 --- a/src/de/steamwar/towerrun/listener/NotLobbyListener.java +++ b/src/de/steamwar/towerrun/listener/NotLobbyListener.java @@ -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.clone().add(0, TowerRun.getTowerGenerator().getHeight(), 0)); + event.getPlayer().teleport(TowerRun.getTowerGenerator().getSpawn()); } else { event.getPlayer().teleport(WorldConfig.SPAWN); } -- 2.39.5 From c55d18f02f436458586f27ccf40bf78e8cde689a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 19 Aug 2023 12:31:34 +0200 Subject: [PATCH 07/13] Fix null location --- src/de/steamwar/towerrun/generator/TowerGenerator.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/de/steamwar/towerrun/generator/TowerGenerator.java b/src/de/steamwar/towerrun/generator/TowerGenerator.java index 07fcc58..ee026d7 100644 --- a/src/de/steamwar/towerrun/generator/TowerGenerator.java +++ b/src/de/steamwar/towerrun/generator/TowerGenerator.java @@ -50,6 +50,7 @@ public class TowerGenerator { this.config = config; allSchematics = SchematicNode.getAllSchematicsOfType(config.schematicType); + spawn = WorldConfig.SPAWN; } private Clipboard loadSchematic(File file) { -- 2.39.5 From a1acde76fd5ed31896dbc3b4d792d2878bec4069 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 19 Aug 2023 12:43:30 +0200 Subject: [PATCH 08/13] Update styling --- .../steamwar/towerrun/config/WorldConfig.java | 3 ++- .../towerrun/countdowns/Countdown.java | 8 ++++++-- .../towerrun/countdowns/EndCountdown.java | 2 +- .../steamwar/towerrun/game/TowerRunGame.java | 18 +++++++++--------- .../towerrun/generator/TowerGenerator.java | 4 ++-- .../towerrun/listener/IngameListener.java | 4 ++-- .../towerrun/listener/LobbyListener.java | 2 +- .../state/GameStateToggleListener.java | 3 ++- .../winconditions/LastOutsideWincondition.java | 6 +++--- 9 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/de/steamwar/towerrun/config/WorldConfig.java b/src/de/steamwar/towerrun/config/WorldConfig.java index f26e12e..1f84875 100644 --- a/src/de/steamwar/towerrun/config/WorldConfig.java +++ b/src/de/steamwar/towerrun/config/WorldConfig.java @@ -58,6 +58,7 @@ public class WorldConfig { public static final TowerGeneratorConfig TOWER_GENERATOR_CONFIG; public static final List WINCONDITIONS = new ArrayList<>(); + static { WINCONDITIONS.add(new LastRemainingWincondition()); WINCONDITIONS.add(new LastOutsideWincondition()); @@ -65,7 +66,7 @@ public class WorldConfig { } private static Location parseLocation(ConfigurationSection section) { - Location loc = new Location( + Location loc = new Location( Bukkit.getWorlds().get(0), section.getDouble("x"), section.getDouble("y"), diff --git a/src/de/steamwar/towerrun/countdowns/Countdown.java b/src/de/steamwar/towerrun/countdowns/Countdown.java index 538eac5..465aa2a 100644 --- a/src/de/steamwar/towerrun/countdowns/Countdown.java +++ b/src/de/steamwar/towerrun/countdowns/Countdown.java @@ -38,9 +38,13 @@ public abstract class Countdown extends GameStateToggleListener { super(enabledStates); } - int defaultTime() {return 0;} + int defaultTime() { + return 0; + } void timerEnd() {} - boolean timerShouldCancel() {return true;} + boolean timerShouldCancel() { + return true; + } void run() {} void timerStart() {} void timerReset() {} diff --git a/src/de/steamwar/towerrun/countdowns/EndCountdown.java b/src/de/steamwar/towerrun/countdowns/EndCountdown.java index b93b9d7..95aa367 100644 --- a/src/de/steamwar/towerrun/countdowns/EndCountdown.java +++ b/src/de/steamwar/towerrun/countdowns/EndCountdown.java @@ -32,7 +32,7 @@ public class EndCountdown extends Countdown { private final LobbyCountdown lobbyCountdown; - private static boolean RESETS = Objects.requireNonNull(Bukkit.getWorlds().get(0).getWorldFolder().list((dir, name) -> name.equals("backup"))).length > 0; + private static final boolean RESETS = Objects.requireNonNull(Bukkit.getWorlds().get(0).getWorldFolder().list((dir, name) -> name.equals("backup"))).length > 0; public EndCountdown(LobbyCountdown lobbyCountdown) { super(EnumSet.of(GameStates.ENDING)); diff --git a/src/de/steamwar/towerrun/game/TowerRunGame.java b/src/de/steamwar/towerrun/game/TowerRunGame.java index 04824a8..c1e17b8 100644 --- a/src/de/steamwar/towerrun/game/TowerRunGame.java +++ b/src/de/steamwar/towerrun/game/TowerRunGame.java @@ -137,33 +137,33 @@ public class TowerRunGame { }); } - private static double posToChunk(int pos){ + private static double posToChunk(int pos) { return pos / 16.0; } - private static int getMinChunkX(){ + private static int getMinChunkX() { return (int) Math.floor(posToChunk(WorldConfig.MAP_MIN_X)); } - private static int getMaxChunkX(){ + private static int getMaxChunkX() { return (int) Math.ceil(posToChunk(WorldConfig.MAP_MAX_X)); } - private static int getMinChunkZ(){ + private static int getMinChunkZ() { return (int) Math.floor(posToChunk(WorldConfig.MAP_MIN_Z)); } - private static int getMaxChunkZ(){ + private static int getMaxChunkZ() { return (int) Math.ceil(posToChunk(WorldConfig.MAP_MAX_Z)); } private static void forEachChunk(ObjIntConsumer executor) { - for(int x = getMinChunkX(); x <= getMaxChunkX(); x++) - for(int z = getMinChunkZ(); z <= getMaxChunkZ(); z++) + for (int x = getMinChunkX(); x <= getMaxChunkX(); x++) + for (int z = getMinChunkZ(); z <= getMaxChunkZ(); z++) executor.accept(x, z); } - private static void resetWorld(){ + private static void resetWorld() { world.getEntities().stream().filter(entity -> entity.getType() != EntityType.PLAYER).forEach(Entity::remove); World backup = new WorldCreator(world.getName() + "/backup").createWorld(); @@ -178,7 +178,7 @@ public class TowerRunGame { System.arraycopy(backupChunk.d(), 0, chunk.d(), 0, chunk.d().length); - for(Player p : Bukkit.getOnlinePlayers()) + for (Player p : Bukkit.getOnlinePlayers()) CraftbukkitWrapper.impl.sendChunk(p, x, z); } } diff --git a/src/de/steamwar/towerrun/generator/TowerGenerator.java b/src/de/steamwar/towerrun/generator/TowerGenerator.java index ee026d7..03d6318 100644 --- a/src/de/steamwar/towerrun/generator/TowerGenerator.java +++ b/src/de/steamwar/towerrun/generator/TowerGenerator.java @@ -31,8 +31,8 @@ public class TowerGenerator { private static final Random random = new Random(); private final WorldConfig.TowerGeneratorConfig config; - private List allSchematics; - private Clipboard roof; + private final List allSchematics; + private final Clipboard roof; @Getter private int height; diff --git a/src/de/steamwar/towerrun/listener/IngameListener.java b/src/de/steamwar/towerrun/listener/IngameListener.java index 5c56088..396e6b1 100644 --- a/src/de/steamwar/towerrun/listener/IngameListener.java +++ b/src/de/steamwar/towerrun/listener/IngameListener.java @@ -48,7 +48,7 @@ import java.util.*; public class IngameListener extends GameStateBukkitListener { private int time = 0; - private Map> blocksToMelt = new HashMap<>(); + private final Map> blocksToMelt = new HashMap<>(); private BukkitRunnable runnable; public IngameListener() { @@ -123,7 +123,7 @@ public class IngameListener extends GameStateBukkitListener { @EventHandler public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { - if(event.getDamager().getType() == EntityType.PLAYER) { + if (event.getDamager().getType() == EntityType.PLAYER) { event.setCancelled(true); } } diff --git a/src/de/steamwar/towerrun/listener/LobbyListener.java b/src/de/steamwar/towerrun/listener/LobbyListener.java index 5c937ed..eb2cb15 100644 --- a/src/de/steamwar/towerrun/listener/LobbyListener.java +++ b/src/de/steamwar/towerrun/listener/LobbyListener.java @@ -57,7 +57,7 @@ public class LobbyListener extends GameStateBukkitListener { 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); } } diff --git a/src/de/steamwar/towerrun/state/GameStateToggleListener.java b/src/de/steamwar/towerrun/state/GameStateToggleListener.java index 85aa0f1..c8ba553 100644 --- a/src/de/steamwar/towerrun/state/GameStateToggleListener.java +++ b/src/de/steamwar/towerrun/state/GameStateToggleListener.java @@ -28,12 +28,13 @@ public abstract class GameStateToggleListener extends GameStateListener { protected GameStateToggleListener(EnumSet enabledStates) { super(); this.enabledStates = enabledStates; - if(enabledStates.contains(GameState.getCurrentState())) { + if (enabledStates.contains(GameState.getCurrentState())) { enable(); } } public abstract void enable(); + public abstract void disable(); @Override diff --git a/src/de/steamwar/towerrun/winconditions/LastOutsideWincondition.java b/src/de/steamwar/towerrun/winconditions/LastOutsideWincondition.java index 7784452..260ed0f 100644 --- a/src/de/steamwar/towerrun/winconditions/LastOutsideWincondition.java +++ b/src/de/steamwar/towerrun/winconditions/LastOutsideWincondition.java @@ -26,7 +26,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.entity.PlayerDeathEvent; -public class LastOutsideWincondition extends OutsideWincondition{ +public class LastOutsideWincondition extends OutsideWincondition { public LastOutsideWincondition() { super("LAST_OUTSIDE"); } @@ -42,8 +42,8 @@ public class LastOutsideWincondition extends OutsideWincondition{ @EventHandler(priority = EventPriority.LOW) public void onPlayerDeath(PlayerDeathEvent event) { - if(TowerRunGame.PLAYERS_ALIVE.isEmpty()) { - if(TowerRunGame.PLAYERS_ESCAPED.isEmpty()) { + if (TowerRunGame.PLAYERS_ALIVE.isEmpty()) { + if (TowerRunGame.PLAYERS_ESCAPED.isEmpty()) { TowerRunGame.tie(); return; } -- 2.39.5 From 4847f9ae0ac18c89cec60f352e7d37ac1f0818d6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 19 Aug 2023 12:46:31 +0200 Subject: [PATCH 09/13] Update styling --- src/de/steamwar/towerrun/winconditions/WinCondition.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/towerrun/winconditions/WinCondition.java b/src/de/steamwar/towerrun/winconditions/WinCondition.java index 355f953..4a736dd 100644 --- a/src/de/steamwar/towerrun/winconditions/WinCondition.java +++ b/src/de/steamwar/towerrun/winconditions/WinCondition.java @@ -40,7 +40,7 @@ public abstract class WinCondition extends GameStateBukkitListener { @Override public void enable() { - if (!active) { + if (active) { super.enable(); } } -- 2.39.5 From 8642a5f4d822305c374a0e860f8091e38c3eb778 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 19 Aug 2023 16:19:54 +0200 Subject: [PATCH 10/13] Add WorldConfig.TowerGeneratorDoorBlock Update TowerGenerator --- configs/mciv.yml | 6 +- configs/steamtower.yml | 40 +++++++++ .../steamwar/towerrun/config/WorldConfig.java | 63 ++++++++++++++ .../towerrun/generator/TowerGenerator.java | 87 ++++++++++++++++++- 4 files changed, 190 insertions(+), 6 deletions(-) diff --git a/configs/mciv.yml b/configs/mciv.yml index 79fc54e..20fce57 100644 --- a/configs/mciv.yml +++ b/configs/mciv.yml @@ -15,11 +15,11 @@ tower: doors: 1: x: 138 - y: 229 + y: 228 z: 858 2: x: 137 - y: 229 + y: 228 z: 858 lavaY: 255 laveSpace: 7 @@ -32,7 +32,7 @@ tower: minX: 93 maxX: 167 minZ: 813 -maxZ: 863 +maxZ: 883 winconditions: - LAST_REMAINING diff --git a/configs/steamtower.yml b/configs/steamtower.yml index 1f820a1..43b94d3 100644 --- a/configs/steamtower.yml +++ b/configs/steamtower.yml @@ -64,6 +64,8 @@ towerGenerator: x: 0 y: 12 z: 0 + minHeight: 200 + maxHeight: 250 schematicType: steamtower fillRegions: 1: @@ -87,6 +89,44 @@ towerGenerator: maxZ: 46 percentage: 1.0 material: MANGROVE_ROOTS + minNoBombFloors: 2 + maxNoBombFloors: 7 + minBombs: 20 + maxBombs: 60 + tntChance: 0.3 + tntRegions: + 1: + minX: 3 + minZ: 3 + maxX: 26 + maxZ: 76 + 2: + minX: 43 + minZ: 3 + maxX: 66 + maxZ: 76 + 3: + minX: 27 + minZ: 53 + maxX: 42 + maxZ: 76 + 4: + minX: 27 + minZ: 3 + maxX: 42 + maxZ: 26 + keyChance: 0.3 + minNoKeyFloors: 2 + maxNoKeyFloors: 7 + doorBlocks: + 1: + x: 30 + dy: 1 + z: 35 + 2: + x: 30 + dy: 1 + z: 36 minX: -28 maxX: 98 diff --git a/src/de/steamwar/towerrun/config/WorldConfig.java b/src/de/steamwar/towerrun/config/WorldConfig.java index 1f84875..fafdd45 100644 --- a/src/de/steamwar/towerrun/config/WorldConfig.java +++ b/src/de/steamwar/towerrun/config/WorldConfig.java @@ -214,13 +214,35 @@ public class WorldConfig { public final int x; public final int y; public final int z; + public final int minHeight; + public final int maxHeight; + public final int minNoBombFloors; + public final int maxNoBombFloors; + public final double tntChance; + public final int minBombs; + public final int maxBombs; + public final double keyChance; + public final int minNoKeyFloors; + public final int maxNoKeyFloors; public final SchematicType schematicType; public final TowerGeneratorFillRegion[] fillRegions; + public final Region[] tntRegions; + public final TowerGeneratorDoorBlock[] doorBlocks; public TowerGeneratorConfig(ConfigurationSection section) { x = section.getInt("x"); y = section.getInt("y"); z = section.getInt("z"); + minHeight = section.getInt("minHeight"); + maxHeight = section.getInt("maxHeight"); + minNoBombFloors = section.getInt("minNoBombFloors"); + maxNoBombFloors = section.getInt("maxNoBombFloors"); + minBombs = section.getInt("minBombs"); + maxBombs = section.getInt("maxBombs"); + tntChance = section.getDouble("tntChance"); + keyChance = section.getDouble("keyChance"); + minNoKeyFloors = section.getInt("minNoKeyFloors"); + maxNoKeyFloors = section.getInt("maxNoKeyFloors"); schematicType = SchematicType.fromDB(section.getString("schematicType")); ConfigurationSection fillRegionsSection = section.getConfigurationSection("fillRegions"); @@ -236,6 +258,34 @@ public class WorldConfig { } else { fillRegions = new TowerGeneratorFillRegion[0]; } + + ConfigurationSection tntRegionsSection = section.getConfigurationSection("tntRegions"); + if (tntRegionsSection != null) { + List tntRegions = tntRegionsSection.getKeys(false).stream() + .map(tntRegionsSection::getConfigurationSection) + .toList(); + + this.tntRegions = new Region[tntRegions.size()]; + for (int i = 0; i < tntRegions.size(); i++) { + this.tntRegions[i] = new Region(tntRegions.get(i)); + } + } else { + tntRegions = new Region[0]; + } + + ConfigurationSection doorBlocksSection = section.getConfigurationSection("doorBlocks"); + if (doorBlocksSection != null) { + List doorBlocks = doorBlocksSection.getKeys(false).stream() + .map(doorBlocksSection::getConfigurationSection) + .toList(); + + this.doorBlocks = new TowerGeneratorDoorBlock[doorBlocks.size()]; + for (int i = 0; i < doorBlocks.size(); i++) { + this.doorBlocks[i] = new TowerGeneratorDoorBlock(doorBlocks.get(i)); + } + } else { + doorBlocks = new TowerGeneratorDoorBlock[0]; + } } } @@ -257,4 +307,17 @@ public class WorldConfig { material = Material.valueOf(section.getString("material")); } } + + @Getter + public static final class TowerGeneratorDoorBlock { + private final int x; + private final int dy; + private final int z; + + public TowerGeneratorDoorBlock(ConfigurationSection section) { + x = section.getInt("x"); + dy = section.getInt("dy"); + z = section.getInt("z"); + } + } } diff --git a/src/de/steamwar/towerrun/generator/TowerGenerator.java b/src/de/steamwar/towerrun/generator/TowerGenerator.java index 03d6318..60d73a8 100644 --- a/src/de/steamwar/towerrun/generator/TowerGenerator.java +++ b/src/de/steamwar/towerrun/generator/TowerGenerator.java @@ -17,12 +17,18 @@ import de.steamwar.towerrun.game.TowerRunGame; import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.block.Block; +import org.bukkit.Material; +import org.bukkit.block.*; +import org.bukkit.block.data.Bisected; +import org.bukkit.block.data.type.Door; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitRunnable; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.Random; @@ -66,11 +72,14 @@ public class TowerGenerator { public void generate() { new BukkitRunnable() { - int height = random.nextInt(50) + 200; + int height = random.nextInt(config.maxHeight - config.minHeight) + config.minHeight; int y = TowerGenerator.this.config.y; + int noBombFloors; + int noKeyFloors; { - TowerGenerator.this.height = height; + noBombFloors = random.nextInt(config.maxNoBombFloors - config.minNoBombFloors) + config.minNoBombFloors; + noKeyFloors = random.nextInt(config.maxNoKeyFloors - config.minNoKeyFloors) + config.minNoKeyFloors; } @Override @@ -79,21 +88,93 @@ public class TowerGenerator { SchematicNode schematicNode = allSchematics.get(random.nextInt(allSchematics.size())); SchematicData schematicData = new SchematicData(schematicNode); int currentY; + int width; + int depth; 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(config.x, y, config.z)).build()); } + width = clipboard.getDimensions().getX(); + depth = clipboard.getDimensions().getZ(); currentY = y; y += clipboard.getDimensions().getY(); height -= clipboard.getDimensions().getY(); + TowerGenerator.this.height += clipboard.getDimensions().getY(); } catch (IOException e) { allSchematics.remove(schematicNode); return; } spawn = WorldConfig.SPAWN.clone().add(0, y, 0); + List chestBlocks = new ArrayList<>(); + for (int x = config.x; x < config.x + width; x++) { + for (int z = config.z; z < config.z + depth; z++) { + for (int y = currentY; y < this.y; y++) { + Block block = Bukkit.getWorlds().get(0).getBlockAt(x, y, z); + BlockState blockState = block.getState(); + if (blockState instanceof Chest) { + chestBlocks.add((Container) blockState); + } + } + } + } + + noBombFloors--; + if (noBombFloors < 0 && random.nextDouble() < config.tntChance) { + noBombFloors = random.nextInt(config.maxNoBombFloors - config.minNoBombFloors) + config.minNoBombFloors; + int bombCount = random.nextInt(config.maxBombs - config.minBombs) + config.minBombs; + for (int i = 0; i < bombCount; i++) { + WorldConfig.Region region = config.tntRegions[random.nextInt(config.tntRegions.length)]; + int x = random.nextInt(region.max.getBlockX() - region.min.getBlockX()) + region.min.getBlockX(); + int z = random.nextInt(region.max.getBlockZ() - region.min.getBlockZ()) + region.min.getBlockZ(); + int y = currentY + 1; + Bukkit.getWorlds().get(0).getBlockAt(x, y, z).setType(Material.TNT, true); + } + } + + noKeyFloors--; + if (!chestBlocks.isEmpty() && noKeyFloors < 0 && random.nextDouble() < config.keyChance) { + noKeyFloors = random.nextInt(config.maxNoKeyFloors - config.minNoKeyFloors) + config.minNoKeyFloors; + Inventory inventory = chestBlocks.get(random.nextInt(chestBlocks.size())).getInventory(); + inventory.addItem(new ItemStack(Material.LEVER, 1)); + + for (WorldConfig.TowerGeneratorDoorBlock doorBlock : config.doorBlocks) { + int x = doorBlock.getX(); + int y = currentY + doorBlock.getDy(); + int z = doorBlock.getZ(); + Block block = Bukkit.getWorlds().get(0).getBlockAt(x, y, z); + for (int i = 0; i < 5; i++) { + if (block.getType().isAir()) { + block.setType(Material.IRON_BLOCK, true); + block = block.getRelative(0, 1, 0); + } else { + break; + } + } + + Bukkit.getScheduler().runTaskLater(TowerRun.getInstance(), () -> { + Block door = Bukkit.getWorlds().get(0).getBlockAt(x, y, z); + door.setType(Material.IRON_DOOR, true); + door = door.getRelative(0, 1, 0); + door.setType(Material.IRON_DOOR, true); + }, 10); + Bukkit.getScheduler().runTaskLater(TowerRun.getInstance(), () -> { + Block door = Bukkit.getWorlds().get(0).getBlockAt(x, y, z); + Door doorState = (Door) door.getBlockData(); + doorState.setFacing(BlockFace.EAST); + door.setBlockData(doorState, true); + + door = door.getRelative(0, 1, 0); + doorState = (Door) door.getBlockData(); + doorState.setFacing(BlockFace.EAST); + doorState.setHalf(Bisected.Half.TOP); + door.setBlockData(doorState, true); + }, 20); + } + } + for (WorldConfig.TowerGeneratorFillRegion fillRegion : config.fillRegions) { for (int x = fillRegion.getMinX(); x < fillRegion.getMaxX(); x++) { for (int z = fillRegion.getMinZ(); z < fillRegion.getMaxZ(); z++) { -- 2.39.5 From 99994de4fdd8e4d552662ad1b782b9d21c4ec26e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 19 Aug 2023 19:07:15 +0200 Subject: [PATCH 11/13] Fix multiple bugs with Spectators and Inventories --- .../towerrun/game/TowerRunPlayer.java | 3 +++ .../towerrun/generator/TowerGenerator.java | 20 ++++++++++-------- .../towerrun/listener/IngameListener.java | 21 +++++++++++++------ 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/de/steamwar/towerrun/game/TowerRunPlayer.java b/src/de/steamwar/towerrun/game/TowerRunPlayer.java index b60ddb7..e7b1297 100644 --- a/src/de/steamwar/towerrun/game/TowerRunPlayer.java +++ b/src/de/steamwar/towerrun/game/TowerRunPlayer.java @@ -44,6 +44,9 @@ public record TowerRunPlayer(Player player) { } public void reset() { + player.getInventory().clear(); + player.updateInventory(); + player.setHealth(20); if (TowerRun.getTowerGenerator() != null) { player.teleport(TowerRun.getTowerGenerator().getSpawn()); } else { diff --git a/src/de/steamwar/towerrun/generator/TowerGenerator.java b/src/de/steamwar/towerrun/generator/TowerGenerator.java index 60d73a8..71bbaba 100644 --- a/src/de/steamwar/towerrun/generator/TowerGenerator.java +++ b/src/de/steamwar/towerrun/generator/TowerGenerator.java @@ -21,8 +21,6 @@ import org.bukkit.Material; import org.bukkit.block.*; import org.bukkit.block.data.Bisected; import org.bukkit.block.data.type.Door; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitRunnable; import java.io.File; @@ -46,6 +44,9 @@ public class TowerGenerator { @Getter private Location spawn; + @Getter + private List keys = new ArrayList<>(); + public TowerGenerator(WorldConfig.TowerGeneratorConfig config) { File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "Roof.schem"); if (!file.exists()) { @@ -80,6 +81,7 @@ public class TowerGenerator { { noBombFloors = random.nextInt(config.maxNoBombFloors - config.minNoBombFloors) + config.minNoBombFloors; noKeyFloors = random.nextInt(config.maxNoKeyFloors - config.minNoKeyFloors) + config.minNoKeyFloors; + keys.clear(); } @Override @@ -137,8 +139,8 @@ public class TowerGenerator { noKeyFloors--; if (!chestBlocks.isEmpty() && noKeyFloors < 0 && random.nextDouble() < config.keyChance) { noKeyFloors = random.nextInt(config.maxNoKeyFloors - config.minNoKeyFloors) + config.minNoKeyFloors; - Inventory inventory = chestBlocks.get(random.nextInt(chestBlocks.size())).getInventory(); - inventory.addItem(new ItemStack(Material.LEVER, 1)); + Container container = chestBlocks.get(random.nextInt(chestBlocks.size())); + keys.add(container.getLocation()); for (WorldConfig.TowerGeneratorDoorBlock doorBlock : config.doorBlocks) { int x = doorBlock.getX(); @@ -147,7 +149,7 @@ public class TowerGenerator { Block block = Bukkit.getWorlds().get(0).getBlockAt(x, y, z); for (int i = 0; i < 5; i++) { if (block.getType().isAir()) { - block.setType(Material.IRON_BLOCK, true); + block.setType(Material.IRON_BLOCK, false); block = block.getRelative(0, 1, 0); } else { break; @@ -156,21 +158,21 @@ public class TowerGenerator { Bukkit.getScheduler().runTaskLater(TowerRun.getInstance(), () -> { Block door = Bukkit.getWorlds().get(0).getBlockAt(x, y, z); - door.setType(Material.IRON_DOOR, true); + door.setType(Material.IRON_DOOR, false); door = door.getRelative(0, 1, 0); - door.setType(Material.IRON_DOOR, true); + door.setType(Material.IRON_DOOR, false); }, 10); Bukkit.getScheduler().runTaskLater(TowerRun.getInstance(), () -> { Block door = Bukkit.getWorlds().get(0).getBlockAt(x, y, z); Door doorState = (Door) door.getBlockData(); doorState.setFacing(BlockFace.EAST); - door.setBlockData(doorState, true); + door.setBlockData(doorState, false); door = door.getRelative(0, 1, 0); doorState = (Door) door.getBlockData(); doorState.setFacing(BlockFace.EAST); doorState.setHalf(Bisected.Half.TOP); - door.setBlockData(doorState, true); + door.setBlockData(doorState, false); }, 20); } } diff --git a/src/de/steamwar/towerrun/listener/IngameListener.java b/src/de/steamwar/towerrun/listener/IngameListener.java index 396e6b1..00b6602 100644 --- a/src/de/steamwar/towerrun/listener/IngameListener.java +++ b/src/de/steamwar/towerrun/listener/IngameListener.java @@ -25,10 +25,7 @@ import de.steamwar.towerrun.config.Config; 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.Material; -import org.bukkit.Sound; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; @@ -44,6 +41,7 @@ import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.scheduler.BukkitRunnable; import java.util.*; +import java.util.stream.Stream; public class IngameListener extends GameStateBukkitListener { @@ -88,6 +86,11 @@ public class IngameListener extends GameStateBukkitListener { @EventHandler public void onPlayerDeath(PlayerDeathEvent event) { event.setDeathMessage(null); + if (TowerRun.getTowerGenerator() != null) { + event.getEntity().teleport(TowerRun.getTowerGenerator().getSpawn()); + } else { + event.getEntity().teleport(WorldConfig.SPAWN); + } event.getEntity().setGameMode(GameMode.SPECTATOR); Bukkit.getOnlinePlayers().forEach(player -> { player.sendTitle("", TowerRun.getMessage().parse("PLAYER_DIED", player, event.getEntity().getPlayer().getName()), 10, 70, 20); @@ -130,6 +133,10 @@ public class IngameListener extends GameStateBukkitListener { @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { + if (event.getPlayer().getGameMode() != GameMode.SURVIVAL) { + return; + } + if (event.getAction() != Action.RIGHT_CLICK_BLOCK || !event.hasBlock()) { return; } @@ -138,13 +145,15 @@ public class IngameListener extends GameStateBukkitListener { return; } - if (Arrays.stream(WorldConfig.KEYS).noneMatch(location -> location.equals(event.getClickedBlock().getLocation()))) { + Stream locations = TowerRun.getTowerGenerator() == null ? Arrays.stream(WorldConfig.KEYS) : TowerRun.getTowerGenerator().getKeys().stream(); + if (locations.noneMatch(location -> location.equals(event.getClickedBlock().getLocation()))) { + event.getClickedBlock().setType(Material.AIR); return; } event.getPlayer().getInventory().addItem(new SWItem(Material.LEVER, TowerRun.getMessage().parse("KEY_NAME", event.getPlayer())).getItemStack()); - event.getClickedBlock().setType(Material.AIR); + event.getClickedBlock().setType(Material.ENDER_CHEST); event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 1, 1); TowerRun.getMessage().broadcast("KEY_FOUND", event.getPlayer().getName()); } -- 2.39.5 From f0f2211fa606904c5e3cb72dadbb73ed30a2c4bf Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 1 Sep 2023 16:17:36 +0200 Subject: [PATCH 12/13] Update steamtower.yml --- configs/steamtower.yml | 96 ++++++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 40 deletions(-) diff --git a/configs/steamtower.yml b/configs/steamtower.yml index 43b94d3..251ae08 100644 --- a/configs/steamtower.yml +++ b/configs/steamtower.yml @@ -5,23 +5,38 @@ tower: maxX: 69 minZ: 0 maxZ: 79 + 2: + minX: 54 + maxX: 74 + minZ: 63 + maxZ: 84 escapeHeight: 1 spawn: x: 66 - y: 25 + y: 12 z: 71 yaw: 180.0 pitch: 0.0 doors: [] keys: [] - lavaY: 76 - laveSpace: 9 + lavaY: 62 + laveSpace: 8 meltingBlocks: + SPRUCE_TRAPDOOR: 10 SMOOTH_STONE: 120 SMOOTH_STONE_SLAB: 60 + STONE_BRICK_SLAB: 60 ANDESITE: 120 + ANDESITE_SLAB: 60 + ANDESITE_WALL: 45 JUKEBOX: 10 IRON_BLOCK: 240 + IRON_DOOR: 60 + IRON_TRAPDOOR: 60 + QUARTZ_SLAB: 30 + QUARTZ_STAIRS: 30 + SMOOTH_RED_SANDSTONE_STAIRS: 30 + SMOOTH_RED_SANDSTONE_SLAB: 30 END_STONE: 240 REDSTONE_LAMP: 30 GLASS: 30 @@ -64,30 +79,23 @@ towerGenerator: x: 0 y: 12 z: 0 - minHeight: 200 - maxHeight: 250 + minHeight: 190 + maxHeight: 240 schematicType: steamtower fillRegions: 1: - minX: 28 - minZ: 30 - maxX: 33 - maxZ: 37 - percentage: 0.3 + minX: 31 + minZ: 29 + maxX: 38 + maxZ: 34 + percentage: 0.25 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 + minX: 31 + minZ: 46 + maxX: 38 + maxZ: 51 + percentage: 0.25 material: MANGROVE_ROOTS minNoBombFloors: 2 maxNoBombFloors: 7 @@ -98,35 +106,43 @@ towerGenerator: 1: minX: 3 minZ: 3 - maxX: 26 - maxZ: 76 + maxX: 30 + maxZ: 77 2: - minX: 43 + minX: 40 minZ: 3 - maxX: 66 - maxZ: 76 + maxX: 67 + maxZ: 77 3: - minX: 27 - minZ: 53 - maxX: 42 - maxZ: 76 - 4: - minX: 27 + minX: 30 minZ: 3 - maxX: 42 - maxZ: 26 - keyChance: 0.3 + maxX: 40 + maxZ: 28 + 4: + minX: 30 + minZ: 52 + maxX: 40 + maxZ: 77 + keyChance: 0.8 minNoKeyFloors: 2 maxNoKeyFloors: 7 doorBlocks: 1: - x: 30 + x: 36 dy: 1 - z: 35 + z: 32 2: - x: 30 + x: 36 dy: 1 - z: 36 + z: 33 + 3: + x: 33 + dy: 1 + z: 46 + 4: + x: 33 + dy: 1 + z: 47 minX: -28 maxX: 98 -- 2.39.5 From d1c0b509843ac20173489541cb71a422b5d25ebf Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 23 Sep 2023 21:23:18 +0200 Subject: [PATCH 13/13] Hotfix StartCommand for indefinite wait Hotfix camping in IngameListener --- src/TowerRun.properties | 1 + src/TowerRun_de.properties | 2 + .../towerrun/commands/StartCommand.java | 6 +- .../towerrun/countdowns/Countdown.java | 2 + .../towerrun/listener/IngameListener.java | 59 ++++++++++++------- 5 files changed, 48 insertions(+), 22 deletions(-) diff --git a/src/TowerRun.properties b/src/TowerRun.properties index a62684d..88c2ecd 100644 --- a/src/TowerRun.properties +++ b/src/TowerRun.properties @@ -31,5 +31,6 @@ KEY_NAME= KEY_FOUND=§a{0} §7found a key§8! GAME_TIE=§aThe game ended in a tie§8! GAME_TIME=§a{0}:{1} +CATCH_UP_WARNING=§4!! §cYou should catch up §4!! COMMAND_START=§aThe game will start soon§8! \ No newline at end of file diff --git a/src/TowerRun_de.properties b/src/TowerRun_de.properties index 0af02df..2c88c3b 100644 --- a/src/TowerRun_de.properties +++ b/src/TowerRun_de.properties @@ -30,4 +30,6 @@ GAME_TIE= KEY_NAME=§eSchlüssel KEY_FOUND=§a{0} §7hat einen Schlüssel gefunden§8! +CATCH_UP_WARNING=§4!! §cDu solltest aufholen §4!! + COMMAND_START=§7Das Spiel startet bald§8! \ No newline at end of file diff --git a/src/de/steamwar/towerrun/commands/StartCommand.java b/src/de/steamwar/towerrun/commands/StartCommand.java index fea225c..ac93fd8 100644 --- a/src/de/steamwar/towerrun/commands/StartCommand.java +++ b/src/de/steamwar/towerrun/commands/StartCommand.java @@ -37,8 +37,10 @@ public class StartCommand extends SWCommand { @Register public void command(@Validator Player player) { - countdown.setOverride(true); - countdown.setTime(10); + if (countdown.getTime() > 10) { + countdown.setOverride(true); + countdown.setTime(10); + } TowerRun.getMessage().send("COMMAND_START", player); } diff --git a/src/de/steamwar/towerrun/countdowns/Countdown.java b/src/de/steamwar/towerrun/countdowns/Countdown.java index 465aa2a..727d19e 100644 --- a/src/de/steamwar/towerrun/countdowns/Countdown.java +++ b/src/de/steamwar/towerrun/countdowns/Countdown.java @@ -22,6 +22,7 @@ package de.steamwar.towerrun.countdowns; import de.steamwar.towerrun.TowerRun; import de.steamwar.towerrun.state.GameStateToggleListener; import de.steamwar.towerrun.state.GameStates; +import lombok.Getter; import lombok.Setter; import org.bukkit.Bukkit; import org.bukkit.scheduler.BukkitTask; @@ -31,6 +32,7 @@ import java.util.EnumSet; public abstract class Countdown extends GameStateToggleListener { @Setter + @Getter protected int time = defaultTime(); protected BukkitTask task; diff --git a/src/de/steamwar/towerrun/listener/IngameListener.java b/src/de/steamwar/towerrun/listener/IngameListener.java index 00b6602..b7de365 100644 --- a/src/de/steamwar/towerrun/listener/IngameListener.java +++ b/src/de/steamwar/towerrun/listener/IngameListener.java @@ -23,6 +23,7 @@ import de.steamwar.inventory.SWItem; import de.steamwar.towerrun.TowerRun; import de.steamwar.towerrun.config.Config; import de.steamwar.towerrun.config.WorldConfig; +import de.steamwar.towerrun.game.TowerRunGame; import de.steamwar.towerrun.state.GameStateBukkitListener; import de.steamwar.towerrun.state.GameStates; import org.bukkit.*; @@ -37,17 +38,18 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.scheduler.BukkitRunnable; import java.util.*; +import java.util.function.Function; import java.util.stream.Stream; public class IngameListener extends GameStateBukkitListener { private int time = 0; private final Map> blocksToMelt = new HashMap<>(); - private BukkitRunnable runnable; + private BukkitRunnable blocksToMeltRunnable; + private BukkitRunnable antiCampRunnable; public IngameListener() { super(EnumSet.of(GameStates.INGAME)); @@ -56,7 +58,7 @@ public class IngameListener extends GameStateBukkitListener { @Override public void enable() { super.enable(); - runnable = new BukkitRunnable() { + blocksToMeltRunnable = new BukkitRunnable() { @Override public void run() { List blocks = blocksToMelt.get(time); @@ -71,26 +73,52 @@ public class IngameListener extends GameStateBukkitListener { }); } }; - runnable.runTaskTimer(TowerRun.getInstance(), 0, 1); + blocksToMeltRunnable.runTaskTimer(TowerRun.getInstance(), 0, 1); + + antiCampRunnable = new BukkitRunnable() { + @Override + public void run() { + double minY = TowerRunGame.PLAYERS_ALIVE.stream() + .map(p -> p.player().getLocation().getY()) + .min(Comparator.comparing(Function.identity())) + .orElse(0.0); + + TowerRunGame.PLAYERS_ALIVE.forEach(towerRunPlayer -> { + if (towerRunPlayer.player().getLocation().getY() - minY > 20) { + towerRunPlayer.player().sendTitle("§a", TowerRun.getMessage().parse("CATCH_UP_WARNING", towerRunPlayer.player()), 5, 30, 5); + } + if (towerRunPlayer.player().getLocation().getY() - minY > 30) { + towerRunPlayer.player().damage(1.0); + } + }); + } + }; + antiCampRunnable.runTaskTimer(TowerRun.getInstance(), 100, 100); } @Override public void disable() { super.disable(); - runnable.cancel(); - runnable = null; + blocksToMeltRunnable.cancel(); + blocksToMeltRunnable = null; blocksToMelt.clear(); time = 0; + + antiCampRunnable.cancel(); + antiCampRunnable = null; } @EventHandler public void onPlayerDeath(PlayerDeathEvent event) { event.setDeathMessage(null); - if (TowerRun.getTowerGenerator() != null) { - event.getEntity().teleport(TowerRun.getTowerGenerator().getSpawn()); - } else { - event.getEntity().teleport(WorldConfig.SPAWN); - } + Bukkit.getScheduler().runTaskLater(TowerRun.getInstance(), () -> { + if (TowerRun.getTowerGenerator() != null) { + event.getEntity().teleport(TowerRun.getTowerGenerator().getSpawn()); + } else { + event.getEntity().teleport(WorldConfig.SPAWN); + } + }, 5 + ); event.getEntity().setGameMode(GameMode.SPECTATOR); Bukkit.getOnlinePlayers().forEach(player -> { player.sendTitle("", TowerRun.getMessage().parse("PLAYER_DIED", player, event.getEntity().getPlayer().getName()), 10, 70, 20); @@ -158,15 +186,6 @@ public class IngameListener extends GameStateBukkitListener { TowerRun.getMessage().broadcast("KEY_FOUND", event.getPlayer().getName()); } - @EventHandler - public void onPlayerRespawn(PlayerRespawnEvent event) { - if (TowerRun.getTowerGenerator() != null) { - event.setRespawnLocation(TowerRun.getTowerGenerator().getSpawn()); - } else { - event.setRespawnLocation(WorldConfig.SPAWN); - } - } - @EventHandler public void onBlockPhysics(BlockPhysicsEvent event) { if (event.getSourceBlock().getType() != Material.LAVA) { -- 2.39.5