2025-06-28 00:36:06 +03:00
|
|
|
package hdvtdev.blockAndSeek.managers;
|
|
|
|
|
|
|
|
|
|
import hdvtdev.blockAndSeek.BlockAndSeek;
|
|
|
|
|
import hdvtdev.blockAndSeek.BlockAndSeekGame;
|
|
|
|
|
import hdvtdev.blockAndSeek.BlockAndSeekMap;
|
|
|
|
|
import hdvtdev.blockAndSeek.Localization;
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
|
import org.bukkit.WorldCreator;
|
|
|
|
|
import org.bukkit.scoreboard.Criteria;
|
|
|
|
|
import org.bukkit.scoreboard.DisplaySlot;
|
|
|
|
|
import org.bukkit.scoreboard.Objective;
|
|
|
|
|
import org.bukkit.scoreboard.Scoreboard;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
|
|
public class GamesManager {
|
|
|
|
|
|
|
|
|
|
private static final ConcurrentHashMap<String, BlockAndSeekGame> games = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
|
|
public static boolean isExist(String name) {
|
|
|
|
|
return games.containsKey(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Set<String> getAvailableGames() {
|
|
|
|
|
return games.keySet();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int createGame(String name) {
|
|
|
|
|
if (games.containsKey(name)) return 1;
|
|
|
|
|
|
|
|
|
|
if (Bukkit.getWorld(name) == null) {
|
|
|
|
|
if (new File(BlockAndSeek.getServerDataFolder(), name).exists()) {
|
|
|
|
|
Bukkit.createWorld(new WorldCreator(name));
|
|
|
|
|
} else return 2;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-01 03:25:09 +03:00
|
|
|
BlockAndSeekMap map = MapsManager.getMap(name);
|
2025-07-02 17:49:15 +03:00
|
|
|
BlockAndSeekGame game = new BlockAndSeekGame(name, map);
|
2025-06-28 00:36:06 +03:00
|
|
|
|
2025-07-02 17:49:15 +03:00
|
|
|
games.put(name, game);
|
2025-06-28 00:36:06 +03:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-02 17:49:15 +03:00
|
|
|
public static void remove(String name) {
|
|
|
|
|
games.remove(name);
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-28 00:36:06 +03:00
|
|
|
public static BlockAndSeekGame get(String name) {
|
|
|
|
|
return games.get(name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Scoreboard updateScoreboard(Scoreboard scoreboard, int players, int maxPlayers) {
|
|
|
|
|
Objective objective = scoreboard.getObjective(DisplaySlot.SIDEBAR);
|
|
|
|
|
for (String o : scoreboard.getEntries()) {
|
|
|
|
|
scoreboard.resetScores(o);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-01 03:25:09 +03:00
|
|
|
|
2025-06-28 00:36:06 +03:00
|
|
|
objective.getScore(" ").setScore(3);
|
|
|
|
|
objective.getScore(Localization.getComponent("game-players-count", "{players}", String.valueOf(players), "{max-players}", String.valueOf(maxPlayers)).toString()).setScore(2);
|
|
|
|
|
objective.getScore(" ").setScore(1);
|
|
|
|
|
objective.getScore(Localization.getComponent("wait-time-left", "{time}", String.valueOf(30)).toString()).setScore(0);
|
|
|
|
|
|
|
|
|
|
return scoreboard;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Scoreboard newLobbyScoreboard(String name, int players, int maxPlayers) {
|
|
|
|
|
Scoreboard scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
|
|
|
|
|
Objective objective = scoreboard.registerNewObjective(name, Criteria.DUMMY, Localization.getComponent(" game-title", "{title}", name));
|
|
|
|
|
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
|
|
|
|
|
|
|
|
|
objective.getScore(" ").setScore(3);
|
|
|
|
|
objective.getScore(Localization.getComponent("game-players-count", "{players}", String.valueOf(players), "{max-players}", String.valueOf(maxPlayers)).toString()).setScore(2);
|
|
|
|
|
objective.getScore(" ").setScore(1);
|
|
|
|
|
objective.getScore(Localization.getComponent("wait-time-left", "{time}", String.valueOf(30)).toString()).setScore(0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return scoreboard;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|