diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/command/ParameterData.java b/src/main/java/link/locutus/discord/commands/manager/v2/command/ParameterData.java index 3c31cee7..d0c280f4 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/command/ParameterData.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/command/ParameterData.java @@ -4,7 +4,7 @@ import com.google.gson.JsonObject; import link.locutus.discord.commands.manager.v2.binding.Key; import link.locutus.discord.commands.manager.v2.binding.Parser; -import link.locutus.discord.commands.manager.v2.binding.annotation.Binding; +import link.locutus.discord.commands.manager.v2.binding.annotation.*; import link.locutus.discord.util.StringMan; import java.lang.annotation.Annotation; @@ -23,7 +23,33 @@ public class ParameterData { public JsonElement toJson() { JsonObject arg = new JsonObject(); - return null; + arg.addProperty("name", getName()); + if (optional) arg.addProperty("optional", true); + if (isFlag()) arg.addProperty("flag", getFlag()); + if (this.desc != null && !desc.isEmpty()) arg.addProperty("desc", desc); + if (group != -1) arg.addProperty("group", group); + arg.addProperty("type", binding.getKey().toSimpleString()); + if (defaultValue != null && defaultValue.length != 0) { + arg.addProperty("default", getDefaultValueString()); + } + ArgChoice choiceAnn = getAnnotation(ArgChoice.class); + if (choiceAnn != null) { + JsonObject choices = new JsonObject(); + for (String choice : choiceAnn.value()) choices.addProperty(choice, choice); + arg.add("choices", choices); + } + Range range = getAnnotation(Range.class); + if (range != null) { + if (range.min() != Double.NEGATIVE_INFINITY) + arg.addProperty("min", range.min()); + if (range.max() != Double.POSITIVE_INFINITY) + arg.addProperty("max", range.max()); + } + Filter filter = getAnnotation(Filter.class); + if (filter != null) { + arg.addProperty("filter", filter.value()); + } + return arg; } public Type getType() { diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/ConflictCommands.java b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/ConflictCommands.java index f6119791..390f8018 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/ConflictCommands.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/ConflictCommands.java @@ -405,6 +405,7 @@ public String addConflict(@Me GuildDB db, ConflictManager manager, @Me JSONObjec reinitializeGraphsArg = "true"; } } + manager.clearAllianceCache(); return response.toString() + "\nThen to initialize the stats and push to the site:\n" + CM.conflict.sync.website.cmd.create(conflict.getId() + "", "true", null, reinitializeGraphsArg); @@ -445,7 +446,7 @@ public String removeCoalition(Conflict conflict, Set alliances) { "This does NOT update conflict stats") @RolePermission(Roles.MILCOM) @CoalitionPermission(Coalition.MANAGE_CONFLICTS) - public String addCoalition(@Me User user, Conflict conflict, Set alliances, @Switch("col1") boolean isCoalition1, @Switch("col2") boolean isCoalition2) { + public String addCoalition(ConflictManager manager, @Me User user, Conflict conflict, Set alliances, @Switch("col1") boolean isCoalition1, @Switch("col2") boolean isCoalition2) { boolean hasAdmin = Roles.ADMIN.hasOnRoot(user); if (isCoalition1 && isCoalition2) { throw new IllegalArgumentException("Cannot specify both `isCoalition1` and `isCoalition2`"); @@ -516,6 +517,7 @@ public String addCoalition(@Me User user, Conflict conflict, Set all for (DBAlliance aa : addCol2) { conflict.addParticipant(aa.getId(), false, null, null); } + manager.clearAllianceCache(); return "Added " + addCol1.size() + " alliances to coalition 1 and " + addCol2.size() + " alliances to coalition 2\n" + "Note: this does NOT update conflict stats"; } diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/GrantCommands.java b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/GrantCommands.java index ec2b68aa..cd2f78e6 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/GrantCommands.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/GrantCommands.java @@ -2165,7 +2165,7 @@ public String templateSend(@Me GuildDB db, @Me Member selfMember, @Me DBNation m @RolePermission(value = {Roles.ECON_STAFF, Roles.ECON, Roles.ECON_WITHDRAW_SELF}, any = true) public String withdrawEscrowed(@Me OffshoreInstance offshore, @Me IMessageIO channel, @Me JSONObject command, @Me GuildDB db, @Me DBNation me, @Me User author, DBNation receiver, Map amount, @Switch("f") boolean force) throws IOException { - if (GuildKey.MEMBER_CAN_ESCROW.getOrNull(db) != Boolean.TRUE) { + if (GuildKey.MEMBER_CAN_ESCROW.getOrNull(db) != Boolean.TRUE && !Roles.ECON_STAFF.has(author, db.getGuild())) { return "To enable member withdrawal of escrowed funds, see: " + CM.settings.info.cmd.create(GuildKey.MEMBER_CAN_ESCROW.name(), null, null); } // Require ECON_STAFF if receiver is not me diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/IACommands.java b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/IACommands.java index affed53d..dd87b972 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/IACommands.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/IACommands.java @@ -87,6 +87,9 @@ public String renameInterviewChannels(@Me GuildDB db, @Me Guild guild, @Me User @Switch("m") boolean allow_non_members, @Switch("v") boolean allow_vm, @Switch("f") boolean force) { + for (Category category : categories) { + if (!category.getGuild().equals(guild)) throw new IllegalArgumentException("Category " + category.getName() + " is not in this guild"); + } Map errors = new LinkedHashMap<>(); Map warnings = new LinkedHashMap<>(); Map> nationChannels = new HashMap<>(); @@ -192,6 +195,9 @@ public String sortChannelsName(@Me GuildDB db, @Me Guild guild, @Me User author, @Default NationFilter filter, @Switch("w") boolean warn_on_filter_fail, @Switch("f") boolean force) { + for (Category category : from) { + if (!category.getGuild().equals(guild)) throw new IllegalArgumentException("Category " + category.getName() + " is not in this guild"); + } List errors = new ArrayList<>(); Map filters = new HashMap<>(); diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/UnsortedCommands.java b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/UnsortedCommands.java index 6dfa1bcb..64a77777 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/UnsortedCommands.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/UnsortedCommands.java @@ -1865,7 +1865,7 @@ public String optimalBuild(@Me JSONObject command, @Me IMessageIO io, @Me Guild if (minPopulation != null) cmd.add("population>" + minPopulation); if (radiation != null) cmd.add("radiation=" + radiation); if (taxRate != null) cmd.add(taxRate.toString()); - if (useRawsForManu) cmd.add("manu=" + useRawsForManu); + if (useRawsForManu) cmd.add("manu=false"); if (writePlaintext) flags.add('p'); if (nationalProjects != null) { for (Project project : nationalProjects) { diff --git a/src/main/java/link/locutus/discord/db/conflict/ConflictManager.java b/src/main/java/link/locutus/discord/db/conflict/ConflictManager.java index fe24cf23..71d0963d 100644 --- a/src/main/java/link/locutus/discord/db/conflict/ConflictManager.java +++ b/src/main/java/link/locutus/discord/db/conflict/ConflictManager.java @@ -240,6 +240,15 @@ private synchronized void initTurn() { } } + public void clearAllianceCache() { + synchronized (mapTurnAllianceConflictOrd) { + mapTurnAllianceConflictOrd.clear(); + lastTurn = 0; + recreateConflictsByAlliance(); + } + } + + private boolean applyConflicts(Predicate allowed, long turn, int allianceId1, int allianceId2, Consumer conflictConsumer) { if (allianceId1 == 0 || allianceId2 == 0) return false; synchronized (mapTurnAllianceConflictOrd) diff --git a/src/main/java/link/locutus/discord/util/offshore/OffshoreInstance.java b/src/main/java/link/locutus/discord/util/offshore/OffshoreInstance.java index 8b8b61f7..cca6b4c7 100644 --- a/src/main/java/link/locutus/discord/util/offshore/OffshoreInstance.java +++ b/src/main/java/link/locutus/discord/util/offshore/OffshoreInstance.java @@ -526,8 +526,9 @@ public TransferResult transferFromNationAccountWithRoleChecks(Supplier