Skip to content

Commit

Permalink
Merge pull request #24 from Alan19/feature/reroll
Browse files Browse the repository at this point in the history
Feature/reroll
  • Loading branch information
Alan19 committed May 20, 2021
2 parents a70a00c + aececd7 commit 4a56fcb
Show file tree
Hide file tree
Showing 19 changed files with 284 additions and 303 deletions.
2 changes: 0 additions & 2 deletions resources/rollLines.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
Are you feeling lucky?
More doom to the DM!
Enjoy!
Here's some help!
Are you sure this is a good idea?
This is the moment of truth!
Doom for the Game Master!
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/commands/BleedCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
import org.javacord.api.entity.message.embed.EmbedBuilder;
import org.javacord.api.entity.permission.Role;
import org.javacord.api.entity.user.User;
import players.PartyHandler;
import sheets.PlotPointHandler;
import sheets.SheetsHandler;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
Expand All @@ -26,13 +24,8 @@ public class BleedCommand implements CommandExecutor {
@Command(aliases = {"~b", "~bleed"}, description = "Applies plot point bleed to a party", privateMessages = false, usage = "~b <roleping>")
public void executeBleed(DiscordApi api, Message message, MessageAuthor author, TextChannel channel, Object[] parameters) {
final List<Role> parties = new ArrayList<>(message.getMentionedRoles());
// Add party roles mentioned by strings to parties
Arrays.stream(parameters)
.filter(partyName -> partyName instanceof String)
.forEach(partyName -> PartyHandler.getPartyByName((String) partyName).flatMap(party -> api.getRoleById(party.getRoleID())).ifPresent(parties::add));
// If there is a number, run the replenish function using the parties and that number as the amount to replenish
bleedParty(parties.get(0), channel, author);

}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/commands/PlotPointCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private void addPlotPointsAndSendSummary(List<User> targets, int amount, TextCha
// TODO Log errors
final List<CompletableFuture<Optional<Integer>>> plotPointUpdateFuture = targets.stream()
.filter(user -> SheetsHandler.getPlotPoints(user).isPresent())
.map(user -> PlotPointHandler.addPlotPointsToUser(amount, changes, new ArrayList<>(), user))
.map(user -> PlotPointHandler.addPlotPointsToUser(user, amount, changes, new ArrayList<>()))
.collect(Collectors.toList());
CompletableFuture.allOf(plotPointUpdateFuture.toArray(new CompletableFuture[]{}))
.thenApply(unused -> channel.sendMessage(PlotPointHandler.generateEmbed(changes, channel, author)));
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/commands/ReplenishCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.javacord.api.entity.message.embed.EmbedBuilder;
import org.javacord.api.entity.permission.Role;
import org.javacord.api.entity.user.User;
import players.PartyHandler;
import sheets.PlotPointHandler;
import sheets.SheetsHandler;

Expand All @@ -25,10 +24,6 @@ public class ReplenishCommand implements CommandExecutor {
@Command(aliases = {"~replenish", "~sr", "~p addall"}, description = "Adds plot points to all party members of the specified party", privateMessages = false, usage = "~replenish <roleping> [amount]")
public void replenishPlotPoints(DiscordApi api, TextChannel channel, Message message, MessageAuthor author, Object[] parameters) {
final List<Role> parties = new ArrayList<>(message.getMentionedRoles());
// Add party roles mentioned by strings to parties
Arrays.stream(parameters)
.filter(partyName -> partyName instanceof String)
.forEach(partyName -> PartyHandler.getPartyByName((String) partyName).flatMap(party -> api.getRoleById(party.getRoleID())).ifPresent(parties::add));
// If there is a number, run the replenish function using the parties and that number as the amount to replenish
Arrays.stream(parameters)
.filter(o -> o instanceof Long).findFirst()
Expand All @@ -50,7 +45,7 @@ private void replenishParties(Role party, int points, TextChannel channel, Messa
List<User> uneditablePlayers = new ArrayList<>();
final List<CompletableFuture<Optional<Integer>>> replenishmentFutures = party.getUsers().stream()
.filter(user -> SheetsHandler.getPlotPoints(user).isPresent())
.map(user -> PlotPointHandler.addPlotPointsToUser(points, plotPointChanges, uneditablePlayers, user))
.map(user -> PlotPointHandler.addPlotPointsToUser(user, points, plotPointChanges, uneditablePlayers))
.collect(Collectors.toList());
CompletableFuture.allOf(replenishmentFutures.toArray(new CompletableFuture[]{}))
.thenAccept(unused -> sendReplenishmentResultEmbed(channel, author, plotPointChanges, uneditablePlayers));
Expand Down
Loading

0 comments on commit 4a56fcb

Please sign in to comment.