use of com.voxelgameslib.voxelgameslib.api.exception.VoxelGameLibException in project VoxelGamesLibv2 by VoxelGamesLib.
the class MojangUtil method getDisplayName.
// TODO we need to do some caching to not break mojang api rate limits
/**
* Tries to fetch the current display name for the user
*
* @param id the id of the user to check
* @return the current display name of that user
* @throws IOException if something goes wrong
* @throws VoxelGameLibException if the user has no display name
*/
@Nonnull
public static String getDisplayName(@Nonnull UUID id) throws IOException, VoxelGameLibException {
URL url = new URL(NAME_HISTORY_URL.replace("%1", id.toString().replace("-", "")));
System.out.println(url.toString());
Scanner scanner = new Scanner(new BufferedReader(new InputStreamReader(url.openStream())));
if (scanner.hasNext()) {
String json = scanner.nextLine();
try {
JSONArray jsonArray = (JSONArray) new JSONParser().parse(json);
if (json.length() > 0) {
return (String) ((JSONObject) jsonArray.get(0)).get("name");
}
} catch (ParseException ignore) {
}
}
throw new VoxelGameLibException("User has no name! " + id);
}
use of com.voxelgameslib.voxelgameslib.api.exception.VoxelGameLibException in project VoxelGamesLibv2 by VoxelGamesLib.
the class AbstractPhase method checkEnd.
private void checkEnd() {
// check all victory conditions
User winner = null;
Team winnerTeam = null;
for (VictoryCondition victoryCondition : victoryConditions) {
if (!victoryCondition.completed()) {
return;
}
if (victoryCondition.getWinner() != null) {
if (!victoryCondition.getWinner().equals(winner)) {
if (winner == null) {
if (winnerTeam != null && !winnerTeam.contains(victoryCondition.getWinner())) {
throw new VoxelGameLibException(victoryCondition.getName() + " defined a winner even tho we already have a winning team!");
}
winner = victoryCondition.getWinner();
} else {
throw new VoxelGameLibException(victoryCondition.getName() + " defined a different winner than one of the conditions before it!");
}
}
}
if (victoryCondition.getWinnerTeam() != null) {
if (!victoryCondition.getWinnerTeam().equals(winnerTeam)) {
if (winnerTeam == null) {
if (winner != null && !victoryCondition.getWinnerTeam().contains(winner)) {
throw new VoxelGameLibException(victoryCondition.getName() + " defined a winning team even tho we already have a winning user!");
} else {
winnerTeam = victoryCondition.getWinnerTeam();
}
} else {
throw new VoxelGameLibException(victoryCondition.getName() + " defined a different winning team than one of the conditions before it!");
}
}
}
}
// all done, end this game
getGame().endGame(winnerTeam, winner);
}
Aggregations