private void saveGameWithinTransaction(Game game, boolean updateDateSaved) { long dateSaved = updateDateSaved ? System.currentTimeMillis() : game.getDateSaved(); game.setDateSaved(dateSaved); if (game.getId() != -1) { // game was already saved, so try to overwrite updateGame(game.getId(), game.getDateStarted(), game.getDateSaved(), game.getName()); } else { // else create a new row in the table int newGameId = getMaxGameId() + 1; ContentValues contentValues = new ContentValues(); contentValues.put(COLUMN_DATE_STARTED, game.getDateStarted()); contentValues.put(COLUMN_DATE_SAVED, dateSaved); contentValues.put(COLUMN_NAME, game.getName()); contentValues.put(COLUMN_ID, newGameId); contentValues.put(COLUMN_AUTOSAVED, 1); // legacy "autosaved" column // that must be specified db.insert(TABLE_GAMES, null, contentValues); game.setId(newGameId); log.d("new game id is %s", newGameId); } savePlayerScores(game.getId(), game.getPlayerScores()); }
@Override protected Map<String, Object> toStringParts() { // @formatter:off return unmodifiableMapOf( entry("name", name), entry("game", game.getName()), entry("version", version)); // @formatter:on }
@GET @Path("RestoreDebugTeams") public String restoreDebugTeams() { List<Game> findNoDebugTeamGames = this.findNoDebugTeamGames(); int counter = 0; for (Game g : findNoDebugTeamGames) { logger.error("Restore Game: " + g.getName() + "/" + g.getId()); DebugTeam dt = new DebugTeam(); g.addTeam(dt); this.getEntityManager().persist(dt); g.getGameModel().propagateDefaultInstance(dt, true); this.getEntityManager().flush(); if (++counter == 25) { break; } } Long remaining = this.countOrphans(); return "OK" + (remaining > 0 ? "(still " + remaining + ")" : ""); }
public void update() { // System.out.println(gameid); if (msgqueue.size() > 0) { display(); Bukkit.getScheduler() .scheduleSyncDelayedTask( GameManager.getInstance().getPlugin(), new Runnable() { @Override public void run() { display(); update(); } }, 20L); return; } clear(); final Game game = GameManager.getInstance().getGame(gameid); final Sign s0 = signs.get(0); final Sign s1 = signs.get(1); // sign 0 s0.setLine(0, "[HungerGames]"); s0.setLine(1, "Click to join"); s0.setLine(2, "Arena " + gameid); // sign 1 s1.setLine(0, game.getName()); s1.setLine(1, game.getMode() + ""); s1.setLine( 2, game.getActivePlayers() + "/" + ChatColor.GRAY + game.getInactivePlayers() + ChatColor.BLACK + "/" + SettingsManager.getInstance().getSpawnCount(game.getID())); // live update line s1 if (game.getMode() == Game.GameMode.STARTING) { s1.setLine(3, game.getCountdownTime() + ""); } else if (game.getMode() == Game.GameMode.RESETING || game.getMode() == Game.GameMode.FINISHING) { s1.setLine(3, game.getRBStatus()); if (game.getRBPercent() > 100) { s1.setLine(1, "Saving Queue"); s1.setLine(3, (int) game.getRBPercent() + " left"); } else s1.setLine(3, (int) game.getRBPercent() + "%"); } else { s1.setLine(3, ""); } // live player data final ArrayList<String> display = new ArrayList<String>(); for (final Player p : game.getAllPlayers()) { display.add((game.isPlayerActive(p) ? ChatColor.BLACK : ChatColor.GRAY) + p.getName()); } try { int no = 2; int line = 0; for (final String s : display) { signs.get(no).setLine(line, s); line++; if (line >= 4) { line = 0; no++; } } } catch (final Exception e) { } for (final Sign s : signs) { s.update(); } }
public static void main(String[] args) throws IOException { String indexHTML = new String(Files.readAllBytes(Paths.get("index.html"))); String createHTML = new String(Files.readAllBytes(Paths.get("create.html"))); Spark.port(80); Spark.get( "/create-submit", (request, response) -> { Game newGame = new Game(request.queryParams("name"), Integer.valueOf(request.queryParams("size"))); games.put(newGame.hashCode(), newGame); // response.redirect("/game/" + newGame.hashCode()); response.redirect("/"); return "success"; }); Spark.get( "/create", (request, response) -> { return createHTML; }); Spark.get( "/game/:gameID/:player/:x/:y/:xOffset/:yOffset", (request, response) -> { Game game = games.get(Integer.parseInt(request.params(":gameID"))); game.update( Integer.parseInt(request.params(":x")), Integer.parseInt(request.params(":y")), request.params(":player"), Integer.parseInt(request.params(":xOffset")), Integer.parseInt(request.params(":yOffset"))); return game.draw(request.params(":player")); }); Spark.get( "/game/:gameID/:player/:x/:y", (request, response) -> { Game game = games.get(Integer.parseInt(request.params(":gameID"))); game.update( Integer.parseInt(request.params(":x")), Integer.parseInt(request.params(":y")), request.params(":player"), 1, 1); return game.draw(request.params(":player")); }); Spark.get( "/game/:gameID/:player", (request, response) -> { return games .get(Integer.parseInt(request.params(":gameID"))) .draw(request.params(":player")); }); Spark.get( "/game/:gameID", (request, response) -> { return ""; }); // default route, home page Spark.get( "/", (request, response) -> { StringBuilder gameList = new StringBuilder(); ArrayList<Game> gamesList = new ArrayList<>(games.values()); Collections.sort(gamesList); for (Game game : gamesList) { gameList.append( " " + game.getName() + "\t<a href=\"/game/" + game.hashCode() + "/green\">Green</a>\t<a href=\"/game/" + game.hashCode() + "/red\">Red</a>\n" + " </br>\n"); } return indexHTML.replace("<!--INSERT_GAME_LIST-->", gameList.toString()); }); }