diff --git a/src/TowerRun.properties b/src/TowerRun.properties index 89728d2..d441ca5 100644 --- a/src/TowerRun.properties +++ b/src/TowerRun.properties @@ -17,13 +17,15 @@ # along with this program. If not, see . # -PREFIX=§eTowerRun§8» §r +PREFIX=§eTowerRun§8»§r PLAYER_DIED=§c{0} §7died§8! GAME_START=§aThe game has started§8! GAME_WIN=§a{0} §7has won the game§8! GAME_STARTING=§7Starting: §e{0}s§8! -GAME_WAITING=§7Waiting for players§8! +GAME_WAITING=§7Waiting for players§8... SERVER_STOPPING=§cThe server stops in §e{0}s§8! +KEY_NAME=§eKey +KEY_FOUND=§a{0} §7found a key§8! 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 31726bc..24dc10f 100644 --- a/src/TowerRun_de.properties +++ b/src/TowerRun_de.properties @@ -22,4 +22,9 @@ GAME_START= GAME_WIN=§a{0} §7hat das Spiel gewonnen§8! GAME_STARTING=§7Das Spiel startet in §e{0}s§8! GAME_WAITING=§7Warte auf weitere Spieler§8... -SERVER_STOPPING=§cDer Server stoppt in §e{0}s§8! \ No newline at end of file +SERVER_STOPPING=§cDer Server stoppt in §e{0}s§8! + +KEY_NAME=§eSchlüssel +KEY_FOUND=§a{0} §7hat einen Schlüssel gefunden§8! + +COMMAND_START=§7Das Spiel startet bald§8! \ No newline at end of file diff --git a/src/de/steamwar/towerrun/config/WorldConfig.java b/src/de/steamwar/towerrun/config/WorldConfig.java index e65ceed..73453e1 100644 --- a/src/de/steamwar/towerrun/config/WorldConfig.java +++ b/src/de/steamwar/towerrun/config/WorldConfig.java @@ -41,6 +41,7 @@ public class WorldConfig { public static final Region[] REGIONS; public static final Location[] DOORS; + public static final Location[] KEYS; public static final int LAVA_Y; public static final int LAVE_SPACE; public static final Location SPAWN; @@ -126,6 +127,14 @@ public class WorldConfig { DOORS[i] = parseLocation(doors.get(i)); } + 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)); + } + LAVA_Y = tower.getInt("lavaY"); LAVE_SPACE = tower.getInt("laveSpace"); ACTIVE_WINCONDITIONS = config.getStringList("winconditions"); diff --git a/src/de/steamwar/towerrun/game/TowerRunGame.java b/src/de/steamwar/towerrun/game/TowerRunGame.java index 365b4a7..a75df1d 100644 --- a/src/de/steamwar/towerrun/game/TowerRunGame.java +++ b/src/de/steamwar/towerrun/game/TowerRunGame.java @@ -23,6 +23,7 @@ import de.steamwar.towerrun.TowerRun; import de.steamwar.towerrun.config.WorldConfig; import de.steamwar.towerrun.state.GameState; import de.steamwar.towerrun.state.GameStates; +import lombok.experimental.UtilityClass; import org.bukkit.*; import org.bukkit.util.Vector; @@ -30,6 +31,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +@UtilityClass public class TowerRunGame { public static final List PLAYERS_ALIVE = new ArrayList<>(); public static final List PLAYERS_ESCAPED = new ArrayList<>(); @@ -75,7 +77,6 @@ public class TowerRunGame { public static void win(TowerRunPlayer tPlayer) { Bukkit.getOnlinePlayers().forEach(player -> player.setGameMode(GameMode.SPECTATOR)); PLAYERS_ALIVE.clear(); - tPlayer.player().teleport(WorldConfig.SPAWN); tPlayer.player().setGameMode(GameMode.SPECTATOR); TowerRun.getMessage().broadcast("GAME_WIN", tPlayer.player().getName()); Bukkit.getOnlinePlayers().forEach(player -> { diff --git a/src/de/steamwar/towerrun/listener/IngameListener.java b/src/de/steamwar/towerrun/listener/IngameListener.java index 48d2667..26690fd 100644 --- a/src/de/steamwar/towerrun/listener/IngameListener.java +++ b/src/de/steamwar/towerrun/listener/IngameListener.java @@ -19,8 +19,10 @@ package de.steamwar.towerrun.listener; +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.state.GameStateBukkitListener; import de.steamwar.towerrun.state.GameStates; import org.bukkit.Bukkit; @@ -28,12 +30,15 @@ import org.bukkit.Material; import org.bukkit.Sound; 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.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 java.util.Arrays; import java.util.EnumSet; public class IngameListener extends GameStateBukkitListener { @@ -45,7 +50,7 @@ public class IngameListener extends GameStateBukkitListener { public void onPlayerDeath(PlayerDeathEvent event) { event.setDeathMessage(null); Bukkit.getOnlinePlayers().forEach(player -> { - player.sendTitle("", TowerRun.getMessage().parse("PLAYER_DIED", player, event.getEntity().getPlayer()), 10, 70, 20); + 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); }); } @@ -63,6 +68,7 @@ public class IngameListener extends GameStateBukkitListener { if (event.getBlockPlaced().getType() == Material.LEVER) { event.setCancelled(true); if (event.getBlockAgainst().getType() == Material.IRON_DOOR) { + event.setCancelled(false); event.getBlockPlaced().breakNaturally(); event.getBlockAgainst().breakNaturally(); event.getItemInHand().setType(Material.AIR); @@ -81,4 +87,25 @@ public class IngameListener extends GameStateBukkitListener { event.setCancelled(true); } } + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent event) { + if (event.getAction() != Action.RIGHT_CLICK_BLOCK || !event.hasBlock()) { + return; + } + + if (event.getClickedBlock().getType() != Material.CHEST) { + return; + } + + if (Arrays.stream(WorldConfig.KEYS).noneMatch(location -> location.equals(event.getClickedBlock().getLocation()))) { + return; + } + + event.getPlayer().getInventory().addItem(new SWItem(Material.LEVER, TowerRun.getMessage().parse("KEY_NAME", event.getPlayer())).getItemStack()); + + event.getClickedBlock().setType(Material.AIR); + event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 1, 1); + TowerRun.getMessage().broadcast("KEY_FOUND", event.getPlayer().getName()); + } } diff --git a/src/de/steamwar/towerrun/winconditions/LastRemainingWincondition.java b/src/de/steamwar/towerrun/winconditions/LastRemainingWincondition.java index 9957b95..6887df6 100644 --- a/src/de/steamwar/towerrun/winconditions/LastRemainingWincondition.java +++ b/src/de/steamwar/towerrun/winconditions/LastRemainingWincondition.java @@ -24,7 +24,9 @@ import de.steamwar.towerrun.game.TowerRunGame; import de.steamwar.towerrun.game.TowerRunPlayer; import org.bukkit.GameMode; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerQuitEvent; public class LastRemainingWincondition extends WinCondition { @@ -36,10 +38,23 @@ public class LastRemainingWincondition extends WinCondition { public void onPlayerDeath(PlayerDeathEvent event) { TowerRunPlayer tPlayer = TowerRunPlayer.get(event.getEntity()); TowerRunGame.PLAYERS_ALIVE.remove(tPlayer); + TowerRunGame.PLAYERS_ESCAPED.remove(tPlayer); tPlayer.player().teleport(WorldConfig.SPAWN); tPlayer.player().setGameMode(GameMode.SPECTATOR); if (TowerRunGame.PLAYERS_ALIVE.size() == 1 && TowerRunGame.PLAYERS_ESCAPED.isEmpty()) { TowerRunGame.win(TowerRunGame.PLAYERS_ALIVE.get(0)); } } + + @EventHandler(priority = EventPriority.LOW) + public void onPlayerQuit(PlayerQuitEvent event) { + TowerRunPlayer tPlayer = TowerRunPlayer.get(event.getPlayer()); + if (TowerRunGame.isAlive(tPlayer)) { + TowerRunGame.PLAYERS_ALIVE.remove(tPlayer); + TowerRunGame.PLAYERS_ESCAPED.remove(tPlayer); + if (TowerRunGame.PLAYERS_ALIVE.size() == 1 && TowerRunGame.PLAYERS_ESCAPED.isEmpty()) { + TowerRunGame.win(TowerRunGame.PLAYERS_ALIVE.get(0)); + } + } + } } diff --git a/src/de/steamwar/towerrun/winconditions/OutsideWincondition.java b/src/de/steamwar/towerrun/winconditions/OutsideWincondition.java index faab36b..dc91cd8 100644 --- a/src/de/steamwar/towerrun/winconditions/OutsideWincondition.java +++ b/src/de/steamwar/towerrun/winconditions/OutsideWincondition.java @@ -30,8 +30,6 @@ import java.util.Arrays; public abstract class OutsideWincondition extends WinCondition { - private static final double BASE_GRAVITY = -0.0784000015258789; - protected OutsideWincondition(String name) { super(name); } @@ -43,6 +41,7 @@ public abstract class OutsideWincondition extends WinCondition { if (event.getTo().getY() > WorldConfig.ESCAPE_HEIGHT) { return; } + TowerRunPlayer tPlayer = TowerRunPlayer.get(event.getPlayer()); if (!TowerRunGame.isAlive(tPlayer)) { return; @@ -52,7 +51,10 @@ public abstract class OutsideWincondition extends WinCondition { return; } - if (event.getPlayer().getVelocity().getY() != BASE_GRAVITY) { + System.out.println("-".repeat(20)); + System.out.println(event.getTo().getY() - event.getFrom().getY()); + + if (event.getTo().getY() - event.getFrom().getY() == 0) { return; } diff --git a/src/world.yml b/src/world.yml index 7d13b61..62f09d9 100644 --- a/src/world.yml +++ b/src/world.yml @@ -26,6 +26,19 @@ tower: x: 116 y: 167 z: 309 + keys: + 1: + x: 67 + y: 143 + z: 332 + 2: + x: 106 + y: 125 + z: 305 + 3: + x: 89 + y: 89 + z: 316 lavaY: 220 laveSpace: 7