Skip to content

Commit

Permalink
Sort custom sheet nations
Browse files Browse the repository at this point in the history
  • Loading branch information
xdnw committed May 14, 2024
1 parent cc5f337 commit 5b3659a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,26 @@ public String getName(DBNation o) {
return o.getName();
}

@Override
public Set<DBNation> deserializeSelection(ValueStore store, String input) {
Set<DBNation> superSet = super.deserializeSelection(store, input);
List<Function<DBNation, Double>> sortCriteria = List.of(
n -> (double) n.getAlliance_id(),
n -> (double) n.getCities(),
n -> (double) n.getId()
);
return superSet.stream().sorted((n1, n2) -> {
for (Function<DBNation, Double> criteria : sortCriteria) {
double val1 = criteria.apply(n1);
double val2 = criteria.apply(n2);
if (val1 != val2) {
return Double.compare(val1, val2);
}
}
return 0;
}).collect(Collectors.toCollection(LinkedHashSet::new));
}

@NoFormat
@Command(desc = "Add an alias for a selection of Nations")
@RolePermission(value = {Roles.INTERNAL_AFFAIRS_STAFF, Roles.MILCOM, Roles.ECON_STAFF, Roles.FOREIGN_AFFAIRS_STAFF, Roles.ECON, Roles.FOREIGN_AFFAIRS}, any = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,12 @@ public static Map.Entry<Object, String> checkProductionBonus(DBNation nation, Ma
}

private Map.Entry<Object, String> checkBuyRpc(GuildDB db, DBNation nation, Map<Integer, JavaCity> cities) {
if (nation.getCities() > Projects.ACTIVITY_CENTER.maxCities()) return null;
if (nation.getCities() > Projects.ACTIVITY_CENTER.maxCities()) {
if (nation.hasProject(Projects.ACTIVITY_CENTER)) {
return Map.entry("-1", "Go to the projects tab and sell activity center");
}
return null;
}
if (nation.getProjectTurns() > 0 || nation.getFreeProjectSlots() <= 0) return null;
return new AbstractMap.SimpleEntry<>("1", "Go to the projects tab and buy the Activity Center");
}
Expand Down

0 comments on commit 5b3659a

Please sign in to comment.