use of com.voxelgameslib.voxelgameslib.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);
}
use of com.voxelgameslib.voxelgameslib.exception.VoxelGameLibException in project VoxelGamesLibv2 by VoxelGamesLib.
the class LangFormatter method handleClick.
@Nonnull
private static ClickEvent handleClick(@Nonnull String token) {
String[] args = token.split(":");
ClickEvent clickEvent;
if (args.length < 2)
throw new VoxelGameLibException("Can't parse click action (too few args) " + token);
switch(args[1]) {
case "run_command":
clickEvent = new ClickEvent(ClickEvent.Action.RUN_COMMAND, token.replace("click:run_command:", ""));
break;
case "suggest_command":
clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, token.replace("click:suggest_command:", ""));
break;
case "open_url":
clickEvent = new ClickEvent(ClickEvent.Action.OPEN_URL, token.replace("click:open_url:", ""));
break;
case "change_page":
clickEvent = new ClickEvent(ClickEvent.Action.CHANGE_PAGE, token.replace("click:change_page:", ""));
break;
default:
throw new VoxelGameLibException("Can't parse click action (invalid type " + args[1] + ") " + token);
}
return clickEvent;
}
use of com.voxelgameslib.voxelgameslib.exception.VoxelGameLibException in project VoxelGamesLibv2 by VoxelGamesLib.
the class LangFormatter method handleHover.
@Nonnull
private static HoverEvent handleHover(@Nonnull String token) {
String[] args = token.split(":");
HoverEvent hoverEvent;
if (args.length < 2)
throw new VoxelGameLibException("Can't parse hover action (too few args) " + token);
switch(args[1]) {
case "show_text":
hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, parseFormat(token.replace("hover:show_text:", "")));
break;
case "show_item":
hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_ITEM, parseFormat(token.replace("hover:show_item:", "")));
break;
case "show_entity":
hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_ENTITY, parseFormat(token.replace("hover:show_entity:", "")));
break;
default:
throw new VoxelGameLibException("Can't parse hover action (invalid type " + args[1] + ") " + token);
}
return hoverEvent;
}
Aggregations