use of com.gianlu.pyxreborn.Exceptions.PyxException in project PretendYoureXyzzyReborn by devgianlu.
the class PyxClientAdapter method sendMessageBlocking.
public JsonObject sendMessageBlocking(JsonObject req) throws InterruptedException, PyxException {
JsonElement id = req.get(Fields.ID.toString());
if (id == null)
throw new IllegalArgumentException("The request should contain an id!");
requests.put(id.getAsInt(), new IMessageBlocking() {
@Override
public void onMessage(JsonObject resp) {
}
@Override
public void onException(Exception ex) {
}
});
send(req.toString());
synchronized (waitingForResponse) {
waitingForResponse.wait();
if (blockingResp == null)
throw blockingEx;
return blockingResp;
}
}
use of com.gianlu.pyxreborn.Exceptions.PyxException in project PretendYoureXyzzyReborn by devgianlu.
the class GameChatUI method send.
@Override
protected void send(MouseEvent event) {
JsonObject req = client.createRequest(Operations.GAME_CHAT);
req.addProperty(Fields.TEXT.toString(), message.getText());
req.addProperty(Fields.GID.toString(), gameId);
try {
client.sendMessageBlocking(req);
} catch (InterruptedException | PyxException ex) {
UIClient.notifyException(ex);
return;
}
message.setText(null);
}
use of com.gianlu.pyxreborn.Exceptions.PyxException in project PretendYoureXyzzyReborn by devgianlu.
the class GameOptionsUI method apply.
@FXML
public void apply(MouseEvent event) {
JsonObject obj = client.createRequest(Operations.CHANGE_GAME_OPTIONS);
obj.addProperty(Fields.GID.toString(), game.gid);
obj.add(Fields.OPTIONS.toString(), newOptions.toJson());
try {
client.sendMessageBlocking(obj);
} catch (InterruptedException | PyxException ex) {
UIClient.notifyException(ex);
return;
}
stage.close();
}
use of com.gianlu.pyxreborn.Exceptions.PyxException in project PretendYoureXyzzyReborn by devgianlu.
the class GameUI method initialize.
@FXML
public void initialize() {
JsonObject obj = client.createRequest(Operations.GET_GAME);
obj.addProperty(Fields.GID.toString(), game.gid);
try {
game = new CGame(client.sendMessageBlocking(obj).getAsJsonObject(Fields.GAME.toString()));
} catch (InterruptedException | PyxException ex) {
UIClient.notifyException(ex);
return;
}
if (Objects.equals(me.nickname, game.host.nickname)) {
// I am the host
if (game.status == Game.Status.LOBBY)
startGame.setVisible(true);
else
startGame.setVisible(false);
} else {
// I am not the host
startGame.setVisible(false);
}
spectators.setCellFactory(param -> new UserCell());
spectators.setItems(spectatorsList);
players.setCellFactory(param -> new PlayerCell());
players.setItems(playersList);
client.addListener((event, request) -> true, this);
if (isSpectating())
instructions.setText("You're a spectator!");
}
use of com.gianlu.pyxreborn.Exceptions.PyxException in project PretendYoureXyzzyReborn by devgianlu.
the class RegisterUI method register.
@FXML
public void register() {
String nickname = this.nickname.getText();
try {
Client client = new Client(new URI(address.getText()), nickname, null, admin.isSelected() ? adminCode.getText() : null);
if (client.connectBlocking()) {
CUser me;
try {
me = new CUser(client.sendMessageBlocking(client.createRequest(Operations.GET_ME)).getAsJsonObject(Fields.USER.toString()));
} catch (PyxException ex) {
UIClient.notifyException(ex);
return;
}
stage.close();
GlobalChatUI.show(client);
MainUI.show(client, me);
} else {
new Alert(Alert.AlertType.ERROR, "Failed connecting! Nickname may be invalid or server may be full.").show();
}
} catch (InterruptedException | URISyntaxException ex) {
UIClient.notifyException(ex);
}
}
Aggregations