Archiviert
13
0
Dieser Commit ist enthalten in:
Chaoscaot 2023-08-17 15:48:56 +02:00
Ursprung 8e7437efcb
Commit de5a012d9e
Signiert von: Chaoscaot
GPG-Schlüssel-ID: BDF8FADD7D5EDB7A
8 geänderte Dateien mit 82 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -23,7 +23,9 @@ PLAYER_DIED=
GAME_START=§aThe game has started§8! GAME_START=§aThe game has started§8!
GAME_WIN=§a{0} §7has won the game§8! GAME_WIN=§a{0} §7has won the game§8!
GAME_STARTING=§7Starting: §e{0}s§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! 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! COMMAND_START=§aThe game will start soon§8!

Datei anzeigen

@ -23,3 +23,8 @@ GAME_WIN=
GAME_STARTING=§7Das Spiel startet in §e{0}s§8! GAME_STARTING=§7Das Spiel startet in §e{0}s§8!
GAME_WAITING=§7Warte auf weitere Spieler§8... GAME_WAITING=§7Warte auf weitere Spieler§8...
SERVER_STOPPING=§cDer Server stoppt in §e{0}s§8! 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!

Datei anzeigen

@ -41,6 +41,7 @@ public class WorldConfig {
public static final Region[] REGIONS; public static final Region[] REGIONS;
public static final Location[] DOORS; public static final Location[] DOORS;
public static final Location[] KEYS;
public static final int LAVA_Y; public static final int LAVA_Y;
public static final int LAVE_SPACE; public static final int LAVE_SPACE;
public static final Location SPAWN; public static final Location SPAWN;
@ -126,6 +127,14 @@ public class WorldConfig {
DOORS[i] = parseLocation(doors.get(i)); DOORS[i] = parseLocation(doors.get(i));
} }
List<ConfigurationSection> 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"); LAVA_Y = tower.getInt("lavaY");
LAVE_SPACE = tower.getInt("laveSpace"); LAVE_SPACE = tower.getInt("laveSpace");
ACTIVE_WINCONDITIONS = config.getStringList("winconditions"); ACTIVE_WINCONDITIONS = config.getStringList("winconditions");

Datei anzeigen

@ -23,6 +23,7 @@ import de.steamwar.towerrun.TowerRun;
import de.steamwar.towerrun.config.WorldConfig; import de.steamwar.towerrun.config.WorldConfig;
import de.steamwar.towerrun.state.GameState; import de.steamwar.towerrun.state.GameState;
import de.steamwar.towerrun.state.GameStates; import de.steamwar.towerrun.state.GameStates;
import lombok.experimental.UtilityClass;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
@ -30,6 +31,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@UtilityClass
public class TowerRunGame { public class TowerRunGame {
public static final List<TowerRunPlayer> PLAYERS_ALIVE = new ArrayList<>(); public static final List<TowerRunPlayer> PLAYERS_ALIVE = new ArrayList<>();
public static final List<TowerRunPlayer> PLAYERS_ESCAPED = new ArrayList<>(); public static final List<TowerRunPlayer> PLAYERS_ESCAPED = new ArrayList<>();
@ -75,7 +77,6 @@ public class TowerRunGame {
public static void win(TowerRunPlayer tPlayer) { public static void win(TowerRunPlayer tPlayer) {
Bukkit.getOnlinePlayers().forEach(player -> player.setGameMode(GameMode.SPECTATOR)); Bukkit.getOnlinePlayers().forEach(player -> player.setGameMode(GameMode.SPECTATOR));
PLAYERS_ALIVE.clear(); PLAYERS_ALIVE.clear();
tPlayer.player().teleport(WorldConfig.SPAWN);
tPlayer.player().setGameMode(GameMode.SPECTATOR); tPlayer.player().setGameMode(GameMode.SPECTATOR);
TowerRun.getMessage().broadcast("GAME_WIN", tPlayer.player().getName()); TowerRun.getMessage().broadcast("GAME_WIN", tPlayer.player().getName());
Bukkit.getOnlinePlayers().forEach(player -> { Bukkit.getOnlinePlayers().forEach(player -> {

Datei anzeigen

@ -19,8 +19,10 @@
package de.steamwar.towerrun.listener; package de.steamwar.towerrun.listener;
import de.steamwar.inventory.SWItem;
import de.steamwar.towerrun.TowerRun; import de.steamwar.towerrun.TowerRun;
import de.steamwar.towerrun.config.Config; import de.steamwar.towerrun.config.Config;
import de.steamwar.towerrun.config.WorldConfig;
import de.steamwar.towerrun.state.GameStateBukkitListener; import de.steamwar.towerrun.state.GameStateBukkitListener;
import de.steamwar.towerrun.state.GameStates; import de.steamwar.towerrun.state.GameStates;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -28,12 +30,15 @@ import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import java.util.Arrays;
import java.util.EnumSet; import java.util.EnumSet;
public class IngameListener extends GameStateBukkitListener { public class IngameListener extends GameStateBukkitListener {
@ -45,7 +50,7 @@ public class IngameListener extends GameStateBukkitListener {
public void onPlayerDeath(PlayerDeathEvent event) { public void onPlayerDeath(PlayerDeathEvent event) {
event.setDeathMessage(null); event.setDeathMessage(null);
Bukkit.getOnlinePlayers().forEach(player -> { 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); 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) { if (event.getBlockPlaced().getType() == Material.LEVER) {
event.setCancelled(true); event.setCancelled(true);
if (event.getBlockAgainst().getType() == Material.IRON_DOOR) { if (event.getBlockAgainst().getType() == Material.IRON_DOOR) {
event.setCancelled(false);
event.getBlockPlaced().breakNaturally(); event.getBlockPlaced().breakNaturally();
event.getBlockAgainst().breakNaturally(); event.getBlockAgainst().breakNaturally();
event.getItemInHand().setType(Material.AIR); event.getItemInHand().setType(Material.AIR);
@ -81,4 +87,25 @@ public class IngameListener extends GameStateBukkitListener {
event.setCancelled(true); 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());
}
} }

Datei anzeigen

@ -24,7 +24,9 @@ import de.steamwar.towerrun.game.TowerRunGame;
import de.steamwar.towerrun.game.TowerRunPlayer; import de.steamwar.towerrun.game.TowerRunPlayer;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class LastRemainingWincondition extends WinCondition { public class LastRemainingWincondition extends WinCondition {
@ -36,10 +38,23 @@ public class LastRemainingWincondition extends WinCondition {
public void onPlayerDeath(PlayerDeathEvent event) { public void onPlayerDeath(PlayerDeathEvent event) {
TowerRunPlayer tPlayer = TowerRunPlayer.get(event.getEntity()); TowerRunPlayer tPlayer = TowerRunPlayer.get(event.getEntity());
TowerRunGame.PLAYERS_ALIVE.remove(tPlayer); TowerRunGame.PLAYERS_ALIVE.remove(tPlayer);
TowerRunGame.PLAYERS_ESCAPED.remove(tPlayer);
tPlayer.player().teleport(WorldConfig.SPAWN); tPlayer.player().teleport(WorldConfig.SPAWN);
tPlayer.player().setGameMode(GameMode.SPECTATOR); tPlayer.player().setGameMode(GameMode.SPECTATOR);
if (TowerRunGame.PLAYERS_ALIVE.size() == 1 && TowerRunGame.PLAYERS_ESCAPED.isEmpty()) { if (TowerRunGame.PLAYERS_ALIVE.size() == 1 && TowerRunGame.PLAYERS_ESCAPED.isEmpty()) {
TowerRunGame.win(TowerRunGame.PLAYERS_ALIVE.get(0)); 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));
}
}
}
} }

Datei anzeigen

@ -30,8 +30,6 @@ import java.util.Arrays;
public abstract class OutsideWincondition extends WinCondition { public abstract class OutsideWincondition extends WinCondition {
private static final double BASE_GRAVITY = -0.0784000015258789;
protected OutsideWincondition(String name) { protected OutsideWincondition(String name) {
super(name); super(name);
} }
@ -43,6 +41,7 @@ public abstract class OutsideWincondition extends WinCondition {
if (event.getTo().getY() > WorldConfig.ESCAPE_HEIGHT) { if (event.getTo().getY() > WorldConfig.ESCAPE_HEIGHT) {
return; return;
} }
TowerRunPlayer tPlayer = TowerRunPlayer.get(event.getPlayer()); TowerRunPlayer tPlayer = TowerRunPlayer.get(event.getPlayer());
if (!TowerRunGame.isAlive(tPlayer)) { if (!TowerRunGame.isAlive(tPlayer)) {
return; return;
@ -52,7 +51,10 @@ public abstract class OutsideWincondition extends WinCondition {
return; 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; return;
} }

Datei anzeigen

@ -26,6 +26,19 @@ tower:
x: 116 x: 116
y: 167 y: 167
z: 309 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 lavaY: 220
laveSpace: 7 laveSpace: 7