2025-06-22 03:19:06 +03:00
|
|
|
package hdvtdev.blockAndSeek;
|
|
|
|
|
|
2025-06-26 01:18:01 +03:00
|
|
|
import hdvtdev.blockAndSeek.roulette.RouletteCreator;
|
|
|
|
|
import net.kyori.adventure.text.Component;
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
|
|
|
|
|
|
|
|
import java.util.Set;
|
2025-06-22 03:19:06 +03:00
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
|
|
public class GamesManager {
|
|
|
|
|
|
|
|
|
|
private static final ConcurrentHashMap<String, BlockAndSeekGame> games = new ConcurrentHashMap<>();
|
|
|
|
|
|
2025-06-26 01:18:01 +03:00
|
|
|
public static boolean isExist(String name) {
|
|
|
|
|
return games.containsKey(name);
|
2025-06-22 03:19:06 +03:00
|
|
|
}
|
|
|
|
|
|
2025-06-26 01:18:01 +03:00
|
|
|
public static Set<String> getAvailableGames() {
|
|
|
|
|
return games.keySet();
|
2025-06-22 03:19:06 +03:00
|
|
|
}
|
|
|
|
|
|
2025-06-26 01:18:01 +03:00
|
|
|
public static int createGame(String name) {
|
|
|
|
|
if (games.containsKey(name)) return 1;
|
|
|
|
|
if (Bukkit.getWorld(name) == null) return 2;
|
|
|
|
|
BlockAndSeekGame game = new BlockAndSeekGame(name);
|
|
|
|
|
games.put(name, game);
|
|
|
|
|
|
|
|
|
|
new BukkitRunnable() {
|
|
|
|
|
|
|
|
|
|
int duration = 30;
|
|
|
|
|
int waitTime = 10;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
|
|
if (!game.isStarted()) {
|
|
|
|
|
int playerCount = game.playerCount();
|
|
|
|
|
|
|
|
|
|
for (Player player : game.getPlayers()) {
|
|
|
|
|
player.sendActionBar(Component.text("Игроков " + playerCount + "/12"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (playerCount > 1) {
|
|
|
|
|
|
|
|
|
|
if (waitTime == 0) {
|
|
|
|
|
game.start();
|
|
|
|
|
for (Player player : game.getPlayers()) {
|
|
|
|
|
RouletteCreator.createRoulette(player, null, true);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (Player player : game.getPlayers()) {
|
|
|
|
|
player.sendMessage(Component.text("Осталось: " + waitTime));
|
|
|
|
|
}
|
|
|
|
|
waitTime--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else waitTime = 10;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
if (game.hidersCound() == 0) {
|
2025-06-22 03:19:06 +03:00
|
|
|
|
2025-06-26 01:18:01 +03:00
|
|
|
for (Player player : game.getPlayers()) {
|
|
|
|
|
player.sendActionBar(Component.text("Сикеры победили!"));
|
|
|
|
|
//TODO
|
|
|
|
|
}
|
2025-06-22 03:19:06 +03:00
|
|
|
|
2025-06-26 01:18:01 +03:00
|
|
|
game.end();
|
|
|
|
|
games.remove(name);
|
|
|
|
|
this.cancel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (Player player : game.getPlayers()) {
|
|
|
|
|
player.sendActionBar(Component.text("Осталось: " + duration));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (duration == 0) {
|
|
|
|
|
for (Player player : game.getPlayers()) {
|
|
|
|
|
player.sendActionBar(Component.text("Хайдеры победили!"));
|
|
|
|
|
}
|
|
|
|
|
game.end();
|
|
|
|
|
games.remove(name);
|
|
|
|
|
this.cancel();
|
|
|
|
|
} else duration--;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}.runTaskTimer(BlockAndSeek.getInstance(), 0L, 20L);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static BlockAndSeekGame get(String name) {
|
|
|
|
|
return games.get(name);
|
|
|
|
|
}
|
2025-06-22 03:19:06 +03:00
|
|
|
|
|
|
|
|
}
|