use of com.gianlu.pyxreborn.Exceptions.GeneralException in project PretendYoureXyzzyReborn by devgianlu.
the class GameManager method start.
/**
* Starts the game.
*
* @throws GeneralException if the can't be started.
*/
public void start() throws GeneralException {
if (game.players.size() < 3)
throw new GeneralException(ErrorCodes.GAME_NOT_ENOUGH_PLAYERS);
loadCards();
nextRound();
}
use of com.gianlu.pyxreborn.Exceptions.GeneralException in project PretendYoureXyzzyReborn by devgianlu.
the class BaseHandlerWithGame method handleRequest.
@Override
public final JsonObject handleRequest(Server server, @NotNull User user, JsonObject request, JsonObject response) throws GeneralException {
JsonElement gid = request.get(Fields.GID.toString());
if (gid == null)
throw new GeneralException(ErrorCodes.INVALID_REQUEST);
Game game = server.games.findGameById(gid.getAsInt());
if (game == null)
throw new GeneralException(ErrorCodes.GAME_DOESNT_EXIST);
return handleRequest(server, user, game, request, response);
}
use of com.gianlu.pyxreborn.Exceptions.GeneralException in project PretendYoureXyzzyReborn by devgianlu.
the class BaseHandlerWithUser method handleRequest.
@Override
public final JsonObject handleRequest(Server server, JsonObject request, JsonObject response) throws GeneralException {
JsonElement sid = request.get(Fields.SESSION_ID.toString());
if (sid == null)
throw new GeneralException(ErrorCodes.INVALID_REQUEST);
User user = server.users.findBySessionId(sid.getAsString());
if (user == null)
throw new GeneralException(ErrorCodes.NOT_CONNECTED);
return handleRequest(server, user, request, response);
}
use of com.gianlu.pyxreborn.Exceptions.GeneralException in project PretendYoureXyzzyReborn by devgianlu.
the class ChatHandler method handleRequest.
@Override
public JsonObject handleRequest(Server server, @NotNull User user, JsonObject request, JsonObject response) throws GeneralException {
JsonElement text = request.get(Fields.TEXT.toString());
if (text == null)
throw new GeneralException(ErrorCodes.INVALID_REQUEST);
JsonObject obj = Utils.event(Events.CHAT);
obj.addProperty(Fields.NICKNAME.toString(), user.nickname);
obj.add(Fields.TEXT.toString(), text);
server.broadcastMessage(obj);
return successful(response);
}
use of com.gianlu.pyxreborn.Exceptions.GeneralException in project PretendYoureXyzzyReborn by devgianlu.
the class GameChatHandler method handleRequest.
@Override
public JsonObject handleRequest(Server server, @NotNull User user, @NotNull Game game, JsonObject request, JsonObject response) throws GeneralException {
JsonElement text = request.get(Fields.TEXT.toString());
if (text == null)
throw new GeneralException(ErrorCodes.INVALID_REQUEST);
JsonObject obj = Utils.event(Events.GAME_CHAT);
obj.addProperty(Fields.NICKNAME.toString(), user.nickname);
obj.addProperty(Fields.GID.toString(), game.gid);
obj.add(Fields.TEXT.toString(), text);
server.broadcastMessageToPlayers(game, obj);
return successful(response);
}
Aggregations