Commits vergleichen
5 Commits
8642a5f4d8
...
99994de4fd
Autor | SHA1 | Datum | |
---|---|---|---|
|
99994de4fd | ||
|
554bdea9a0 | ||
|
684383a978 | ||
|
b6a668b393 | ||
|
2184434d95 |
@ -30,5 +30,6 @@ SERVER_RESET=
|
|||||||
KEY_NAME=§eKey
|
KEY_NAME=§eKey
|
||||||
KEY_FOUND=§a{0} §7found a key§8!
|
KEY_FOUND=§a{0} §7found a key§8!
|
||||||
GAME_TIE=§aThe game ended in a tie§8!
|
GAME_TIE=§aThe game ended in a tie§8!
|
||||||
|
GAME_TIME=§a{0}:{1}
|
||||||
|
|
||||||
COMMAND_START=§aThe game will start soon§8!
|
COMMAND_START=§aThe game will start soon§8!
|
@ -23,6 +23,7 @@ import de.steamwar.message.Message;
|
|||||||
import de.steamwar.towerrun.commands.StartCommand;
|
import de.steamwar.towerrun.commands.StartCommand;
|
||||||
import de.steamwar.towerrun.config.WorldConfig;
|
import de.steamwar.towerrun.config.WorldConfig;
|
||||||
import de.steamwar.towerrun.countdowns.EndCountdown;
|
import de.steamwar.towerrun.countdowns.EndCountdown;
|
||||||
|
import de.steamwar.towerrun.countdowns.GameCountdown;
|
||||||
import de.steamwar.towerrun.countdowns.LobbyCountdown;
|
import de.steamwar.towerrun.countdowns.LobbyCountdown;
|
||||||
import de.steamwar.towerrun.game.TowerRunGame;
|
import de.steamwar.towerrun.game.TowerRunGame;
|
||||||
import de.steamwar.towerrun.generator.TowerGenerator;
|
import de.steamwar.towerrun.generator.TowerGenerator;
|
||||||
@ -55,6 +56,10 @@ public class TowerRun extends JavaPlugin {
|
|||||||
@Getter
|
@Getter
|
||||||
private static TowerGenerator towerGenerator = null;
|
private static TowerGenerator towerGenerator = null;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private static GameCountdown gameCountdown;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
instance = this;
|
instance = this;
|
||||||
@ -72,6 +77,7 @@ public class TowerRun extends JavaPlugin {
|
|||||||
final LobbyCountdown lobbyCountdown = new LobbyCountdown();
|
final LobbyCountdown lobbyCountdown = new LobbyCountdown();
|
||||||
new EndCountdown(lobbyCountdown);
|
new EndCountdown(lobbyCountdown);
|
||||||
new StartCommand(lobbyCountdown);
|
new StartCommand(lobbyCountdown);
|
||||||
|
gameCountdown = new GameCountdown();
|
||||||
|
|
||||||
TowerRunGame.reset();
|
TowerRunGame.reset();
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,8 @@ public class Config {
|
|||||||
public static final int MIN_PLAYERS;
|
public static final int MIN_PLAYERS;
|
||||||
public static final int LOBBY_TIMER;
|
public static final int LOBBY_TIMER;
|
||||||
public static final Set<Material> DESTROYABLE_BLOCKS;
|
public static final Set<Material> DESTROYABLE_BLOCKS;
|
||||||
|
public static final int GAME_TIMER;
|
||||||
|
public static final int GAME_ESCAPE_TIMER;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
File configFile = new File(TowerRun.getInstance().getDataFolder(), "config.yml");
|
File configFile = new File(TowerRun.getInstance().getDataFolder(), "config.yml");
|
||||||
@ -48,6 +50,8 @@ public class Config {
|
|||||||
|
|
||||||
MIN_PLAYERS = config.getInt("minPlayers");
|
MIN_PLAYERS = config.getInt("minPlayers");
|
||||||
LOBBY_TIMER = config.getInt("lobbyTimer");
|
LOBBY_TIMER = config.getInt("lobbyTimer");
|
||||||
|
GAME_TIMER = config.getInt("gameTimer", 20 * 60);
|
||||||
|
GAME_ESCAPE_TIMER = config.getInt("gameEscapeTimer", 60);
|
||||||
DESTROYABLE_BLOCKS = EnumSet.copyOf(config.getStringList("destroyable").stream().map(Material::valueOf).collect(Collectors.toSet()));
|
DESTROYABLE_BLOCKS = EnumSet.copyOf(config.getStringList("destroyable").stream().map(Material::valueOf).collect(Collectors.toSet()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
61
src/de/steamwar/towerrun/countdowns/GameCountdown.java
Normale Datei
61
src/de/steamwar/towerrun/countdowns/GameCountdown.java
Normale Datei
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.towerrun.countdowns;
|
||||||
|
|
||||||
|
import de.steamwar.towerrun.TowerRun;
|
||||||
|
import de.steamwar.towerrun.config.Config;
|
||||||
|
import de.steamwar.towerrun.game.TowerRunGame;
|
||||||
|
import de.steamwar.towerrun.state.GameStates;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
|
public class GameCountdown extends Countdown {
|
||||||
|
|
||||||
|
public GameCountdown() {
|
||||||
|
super(EnumSet.of(GameStates.INGAME));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
int defaultTime() {
|
||||||
|
return Config.GAME_TIMER;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void timerEnd() {
|
||||||
|
if (TowerRunGame.PLAYERS_ESCAPED.isEmpty()) {
|
||||||
|
TowerRunGame.tie();
|
||||||
|
} else {
|
||||||
|
TowerRunGame.win(TowerRunGame.PLAYERS_ESCAPED.get(TowerRunGame.PLAYERS_ESCAPED.size() - 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
boolean timerShouldCancel() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
void run() {
|
||||||
|
int timeMinutes = Math.floorDiv(time, 60);
|
||||||
|
int timeSeconds = time % 60;
|
||||||
|
|
||||||
|
TowerRun.getMessage().broadcastActionbar("GAME_TIME", String.format("%02d", timeMinutes), String.format("%02d", timeSeconds));
|
||||||
|
}
|
||||||
|
}
|
@ -44,6 +44,9 @@ public record TowerRunPlayer(Player player) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
|
player.getInventory().clear();
|
||||||
|
player.updateInventory();
|
||||||
|
player.setHealth(20);
|
||||||
if (TowerRun.getTowerGenerator() != null) {
|
if (TowerRun.getTowerGenerator() != null) {
|
||||||
player.teleport(TowerRun.getTowerGenerator().getSpawn());
|
player.teleport(TowerRun.getTowerGenerator().getSpawn());
|
||||||
} else {
|
} else {
|
||||||
|
@ -21,8 +21,6 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.block.*;
|
import org.bukkit.block.*;
|
||||||
import org.bukkit.block.data.Bisected;
|
import org.bukkit.block.data.Bisected;
|
||||||
import org.bukkit.block.data.type.Door;
|
import org.bukkit.block.data.type.Door;
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -46,6 +44,9 @@ public class TowerGenerator {
|
|||||||
@Getter
|
@Getter
|
||||||
private Location spawn;
|
private Location spawn;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private List<Location> keys = new ArrayList<>();
|
||||||
|
|
||||||
public TowerGenerator(WorldConfig.TowerGeneratorConfig config) {
|
public TowerGenerator(WorldConfig.TowerGeneratorConfig config) {
|
||||||
File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "Roof.schem");
|
File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "Roof.schem");
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
@ -80,6 +81,7 @@ public class TowerGenerator {
|
|||||||
{
|
{
|
||||||
noBombFloors = random.nextInt(config.maxNoBombFloors - config.minNoBombFloors) + config.minNoBombFloors;
|
noBombFloors = random.nextInt(config.maxNoBombFloors - config.minNoBombFloors) + config.minNoBombFloors;
|
||||||
noKeyFloors = random.nextInt(config.maxNoKeyFloors - config.minNoKeyFloors) + config.minNoKeyFloors;
|
noKeyFloors = random.nextInt(config.maxNoKeyFloors - config.minNoKeyFloors) + config.minNoKeyFloors;
|
||||||
|
keys.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -137,8 +139,8 @@ public class TowerGenerator {
|
|||||||
noKeyFloors--;
|
noKeyFloors--;
|
||||||
if (!chestBlocks.isEmpty() && noKeyFloors < 0 && random.nextDouble() < config.keyChance) {
|
if (!chestBlocks.isEmpty() && noKeyFloors < 0 && random.nextDouble() < config.keyChance) {
|
||||||
noKeyFloors = random.nextInt(config.maxNoKeyFloors - config.minNoKeyFloors) + config.minNoKeyFloors;
|
noKeyFloors = random.nextInt(config.maxNoKeyFloors - config.minNoKeyFloors) + config.minNoKeyFloors;
|
||||||
Inventory inventory = chestBlocks.get(random.nextInt(chestBlocks.size())).getInventory();
|
Container container = chestBlocks.get(random.nextInt(chestBlocks.size()));
|
||||||
inventory.addItem(new ItemStack(Material.LEVER, 1));
|
keys.add(container.getLocation());
|
||||||
|
|
||||||
for (WorldConfig.TowerGeneratorDoorBlock doorBlock : config.doorBlocks) {
|
for (WorldConfig.TowerGeneratorDoorBlock doorBlock : config.doorBlocks) {
|
||||||
int x = doorBlock.getX();
|
int x = doorBlock.getX();
|
||||||
@ -147,7 +149,7 @@ public class TowerGenerator {
|
|||||||
Block block = Bukkit.getWorlds().get(0).getBlockAt(x, y, z);
|
Block block = Bukkit.getWorlds().get(0).getBlockAt(x, y, z);
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
if (block.getType().isAir()) {
|
if (block.getType().isAir()) {
|
||||||
block.setType(Material.IRON_BLOCK, true);
|
block.setType(Material.IRON_BLOCK, false);
|
||||||
block = block.getRelative(0, 1, 0);
|
block = block.getRelative(0, 1, 0);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
@ -156,21 +158,21 @@ public class TowerGenerator {
|
|||||||
|
|
||||||
Bukkit.getScheduler().runTaskLater(TowerRun.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(TowerRun.getInstance(), () -> {
|
||||||
Block door = Bukkit.getWorlds().get(0).getBlockAt(x, y, z);
|
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 = door.getRelative(0, 1, 0);
|
||||||
door.setType(Material.IRON_DOOR, true);
|
door.setType(Material.IRON_DOOR, false);
|
||||||
}, 10);
|
}, 10);
|
||||||
Bukkit.getScheduler().runTaskLater(TowerRun.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(TowerRun.getInstance(), () -> {
|
||||||
Block door = Bukkit.getWorlds().get(0).getBlockAt(x, y, z);
|
Block door = Bukkit.getWorlds().get(0).getBlockAt(x, y, z);
|
||||||
Door doorState = (Door) door.getBlockData();
|
Door doorState = (Door) door.getBlockData();
|
||||||
doorState.setFacing(BlockFace.EAST);
|
doorState.setFacing(BlockFace.EAST);
|
||||||
door.setBlockData(doorState, true);
|
door.setBlockData(doorState, false);
|
||||||
|
|
||||||
door = door.getRelative(0, 1, 0);
|
door = door.getRelative(0, 1, 0);
|
||||||
doorState = (Door) door.getBlockData();
|
doorState = (Door) door.getBlockData();
|
||||||
doorState.setFacing(BlockFace.EAST);
|
doorState.setFacing(BlockFace.EAST);
|
||||||
doorState.setHalf(Bisected.Half.TOP);
|
doorState.setHalf(Bisected.Half.TOP);
|
||||||
door.setBlockData(doorState, true);
|
door.setBlockData(doorState, false);
|
||||||
}, 20);
|
}, 20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,10 +25,7 @@ import de.steamwar.towerrun.config.Config;
|
|||||||
import de.steamwar.towerrun.config.WorldConfig;
|
import de.steamwar.towerrun.config.WorldConfig;
|
||||||
import de.steamwar.towerrun.state.GameStateBukkitListener;
|
import de.steamwar.towerrun.state.GameStateBukkitListener;
|
||||||
import de.steamwar.towerrun.state.GameStates;
|
import de.steamwar.towerrun.state.GameStates;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.*;
|
||||||
import org.bukkit.GameMode;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.Sound;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -44,6 +41,7 @@ import org.bukkit.event.player.PlayerRespawnEvent;
|
|||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class IngameListener extends GameStateBukkitListener {
|
public class IngameListener extends GameStateBukkitListener {
|
||||||
|
|
||||||
@ -88,6 +86,11 @@ public class IngameListener extends GameStateBukkitListener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerDeath(PlayerDeathEvent event) {
|
public void onPlayerDeath(PlayerDeathEvent event) {
|
||||||
event.setDeathMessage(null);
|
event.setDeathMessage(null);
|
||||||
|
if (TowerRun.getTowerGenerator() != null) {
|
||||||
|
event.getEntity().teleport(TowerRun.getTowerGenerator().getSpawn());
|
||||||
|
} else {
|
||||||
|
event.getEntity().teleport(WorldConfig.SPAWN);
|
||||||
|
}
|
||||||
event.getEntity().setGameMode(GameMode.SPECTATOR);
|
event.getEntity().setGameMode(GameMode.SPECTATOR);
|
||||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||||
player.sendTitle("", TowerRun.getMessage().parse("PLAYER_DIED", player, event.getEntity().getPlayer().getName()), 10, 70, 20);
|
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
|
@EventHandler
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
|
if (event.getPlayer().getGameMode() != GameMode.SURVIVAL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK || !event.hasBlock()) {
|
if (event.getAction() != Action.RIGHT_CLICK_BLOCK || !event.hasBlock()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -138,13 +145,15 @@ public class IngameListener extends GameStateBukkitListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Arrays.stream(WorldConfig.KEYS).noneMatch(location -> location.equals(event.getClickedBlock().getLocation()))) {
|
Stream<Location> 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
event.getPlayer().getInventory().addItem(new SWItem(Material.LEVER, TowerRun.getMessage().parse("KEY_NAME", event.getPlayer())).getItemStack());
|
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);
|
event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 1, 1);
|
||||||
TowerRun.getMessage().broadcast("KEY_FOUND", event.getPlayer().getName());
|
TowerRun.getMessage().broadcast("KEY_FOUND", event.getPlayer().getName());
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package de.steamwar.towerrun.winconditions;
|
package de.steamwar.towerrun.winconditions;
|
||||||
|
|
||||||
import de.steamwar.towerrun.TowerRun;
|
import de.steamwar.towerrun.TowerRun;
|
||||||
|
import de.steamwar.towerrun.config.Config;
|
||||||
import de.steamwar.towerrun.config.WorldConfig;
|
import de.steamwar.towerrun.config.WorldConfig;
|
||||||
import de.steamwar.towerrun.game.TowerRunGame;
|
import de.steamwar.towerrun.game.TowerRunGame;
|
||||||
import de.steamwar.towerrun.game.TowerRunPlayer;
|
import de.steamwar.towerrun.game.TowerRunPlayer;
|
||||||
@ -65,5 +66,8 @@ public abstract class OutsideWincondition extends WinCondition {
|
|||||||
TowerRunGame.PLAYERS_ALIVE.remove(towerRunPlayer);
|
TowerRunGame.PLAYERS_ALIVE.remove(towerRunPlayer);
|
||||||
towerRunPlayer.player().setGameMode(GameMode.SPECTATOR);
|
towerRunPlayer.player().setGameMode(GameMode.SPECTATOR);
|
||||||
TowerRun.getMessage().broadcast("PLAYER_ESCAPE", towerRunPlayer.player().getName());
|
TowerRun.getMessage().broadcast("PLAYER_ESCAPE", towerRunPlayer.player().getName());
|
||||||
|
if (TowerRunGame.PLAYERS_ESCAPED.size() == 1) {
|
||||||
|
TowerRun.getGameCountdown().setTime(Config.GAME_ESCAPE_TIMER);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren