Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
xdnw committed May 21, 2024
1 parent 4105b20 commit ee3573f
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -445,7 +446,7 @@ public String removeCoalition(Conflict conflict, Set<DBAlliance> alliances) {
"This does NOT update conflict stats")
@RolePermission(Roles.MILCOM)
@CoalitionPermission(Coalition.MANAGE_CONFLICTS)
public String addCoalition(@Me User user, Conflict conflict, Set<DBAlliance> alliances, @Switch("col1") boolean isCoalition1, @Switch("col2") boolean isCoalition2) {
public String addCoalition(ConflictManager manager, @Me User user, Conflict conflict, Set<DBAlliance> 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`");
Expand Down Expand Up @@ -516,6 +517,7 @@ public String addCoalition(@Me User user, Conflict conflict, Set<DBAlliance> 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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResourceType, Double> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TextChannel, String> errors = new LinkedHashMap<>();
Map<TextChannel, String> warnings = new LinkedHashMap<>();
Map<DBNation, Set<TextChannel>> nationChannels = new HashMap<>();
Expand Down Expand Up @@ -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<String> errors = new ArrayList<>();
Map<Category, NationFilter> filters = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,15 @@ private synchronized void initTurn() {
}
}

public void clearAllianceCache() {
synchronized (mapTurnAllianceConflictOrd) {
mapTurnAllianceConflictOrd.clear();
lastTurn = 0;
recreateConflictsByAlliance();
}
}


private boolean applyConflicts(Predicate<Integer> allowed, long turn, int allianceId1, int allianceId2, Consumer<Conflict> conflictConsumer) {
if (allianceId1 == 0 || allianceId2 == 0) return false;
synchronized (mapTurnAllianceConflictOrd)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,9 @@ public TransferResult transferFromNationAccountWithRoleChecks(Supplier<Map<Long,
return new TransferResult(TransferStatus.INVALID_NOTE, receiver, amount, depositType.toString()).addMessage("Please use `" + DepositType.IGNORE + "` as the `depositType` when transferring to alliances");
}

boolean escrowSetting = GuildKey.MEMBER_CAN_ESCROW.get(senderDB) == Boolean.TRUE;
boolean allowEscrow = escrowMode == EscrowMode.ALWAYS || (escrowMode == EscrowMode.WHEN_BLOCKADED && receiver.isNation());
boolean escrowFunds = receiver.isNation() && receiver.asNation().isBlockaded();
boolean escrowFunds = (allowEscrow || escrowSetting) && receiver.isNation() && receiver.asNation().isBlockaded();

if (!bypassChecks && receiver.isNation()) {
DBNation nation = receiver.asNation();
Expand Down

0 comments on commit ee3573f

Please sign in to comment.