idk some "cool" stuff
This commit is contained in:
@@ -1,25 +1,106 @@
|
||||
package hdvtdev.blockAndSeek;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
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;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class GamesManager {
|
||||
|
||||
private static final ConcurrentHashMap<String, BlockAndSeekGame> games = new ConcurrentHashMap<>();
|
||||
|
||||
public static void createGame(String name, ArrayList<String> players) {
|
||||
games.put(name, new BlockAndSeekGame(name, players));
|
||||
public static boolean isExist(String name) {
|
||||
return games.containsKey(name);
|
||||
}
|
||||
|
||||
public static boolean joinGame(String name) {
|
||||
return false;
|
||||
public static Set<String> getAvailableGames() {
|
||||
return games.keySet();
|
||||
}
|
||||
|
||||
public static void endGame(String name) {
|
||||
games.remove(name);
|
||||
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) {
|
||||
|
||||
for (Player player : game.getPlayers()) {
|
||||
player.sendActionBar(Component.text("Сикеры победили!"));
|
||||
//TODO
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user