Skip to content

Commit

Permalink
Update POM, fix doom writer not accessing bot.properties properly. Ad…
Browse files Browse the repository at this point in the history
…d GM's ID in bot.properties instead of in code.
  • Loading branch information
Alan19 committed Nov 11, 2018
1 parent 4be57de commit 6b9c16b
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 34 deletions.
30 changes: 29 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,35 @@
<artifactId>sdcf4j-javacord</artifactId>
<version>v1.0.10</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.0.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.0.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
<version>1.3.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
<version>1.3.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>


</dependencies>
Expand Down
52 changes: 31 additions & 21 deletions src/main/java/logic/CommandHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
import org.javacord.api.entity.message.embed.EmbedBuilder;
import sheets.SheetsQuickstart;

import java.io.FileInputStream;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.ExecutionException;

public class CommandHandler {

Expand Down Expand Up @@ -93,31 +96,38 @@ private EmbedBuilder commandSelector(String message) {
case "~r":
case "~roll":
//Special case for GM
if (author.equals(api.getUserById("73478860120797184"))){
if (commandContainsPlotDice(message)){
DoomWriter writer = new DoomWriter();
writer.addDoom(getPlotPointsSpent(message) * -1);
writer.generateDoomEmbed();
try {
Properties prop = new Properties();
prop.load(new FileInputStream("resources/bot.properties"));
if (author.getIdAsString().equals(prop.getProperty("gameMaster"))){
if (commandContainsPlotDice(message)){
DoomWriter writer = new DoomWriter();
writer.addDoom(getPlotPointsSpent(message) * -1);
EmbedBuilder doomEmbed = writer.generateDoomEmbed();
channel.sendMessage(doomEmbed);
}
}
}
else {
message = handleCommand();
assert message != null;
DiceRoller diceRoller = new DiceRoller(message);
deductPlotPoints(message);

new MessageBuilder()
.setEmbed(diceRoller.generateResults(author))
.send(channel);
EmbedBuilder doomEmbed = diceRoller.addPlotPoints(author, api);
if (doomEmbed != null) {
new MessageBuilder()
.setEmbed(doomEmbed)
.send(channel);
else {
message = handleCommand();
assert message != null;
DiceRoller diceRoller = new DiceRoller(message);
deductPlotPoints(message);

new MessageBuilder()
.setEmbed(diceRoller.addDoom(diceRoller.getDoom()))
.setEmbed(diceRoller.generateResults(author))
.send(channel);
EmbedBuilder doomEmbed = diceRoller.addPlotPoints(author, api);
if (doomEmbed != null) {
new MessageBuilder()
.setEmbed(doomEmbed)
.send(channel);
new MessageBuilder()
.setEmbed(diceRoller.addDoom(diceRoller.getDoom()))
.send(channel);
}
}
} catch (IOException e) {
e.printStackTrace();
}

break;
Expand Down
39 changes: 27 additions & 12 deletions src/main/java/logic/DoomWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public class DoomWriter {

public DoomWriter() {
prop = new Properties();
try {
prop.load(new FileInputStream("resources/bot.properties"));
} catch (IOException e) {
e.printStackTrace();
}
}

public EmbedBuilder addDoom(int doomVal) {
Expand All @@ -28,26 +33,36 @@ public EmbedBuilder generateDoomEmbed() {
return new EmbedBuilder()
.setTitle("Doom!")
.setDescription(String.valueOf(getDoom()))
.setColor(new Color(doomVal, doomVal, doomVal));
.setColor(new Color(Integer.max(doomVal, 255)));
}

public int getDoom() {
try {
prop.load(new FileInputStream("resources/bot.properties"));
} catch (IOException e) {
e.printStackTrace();
}
return Integer.parseInt(prop.getProperty("doom"));
}

/**
* Sets the doom on the properties file. If doom points would drop below 0, return an error.
* @param newDoom
* @return The embed with a new doom value
*/
public EmbedBuilder setDoom(int newDoom) {
prop.setProperty("doom", String.valueOf(newDoom));
try {
prop.store(new FileOutputStream("resources/bot.properties"), null);
} catch (IOException e) {
e.printStackTrace();
if (newDoom < 0){
return generateInvalidDoomEmbed();
}
return generateDoomEmbed();
else {
prop.setProperty("doom", String.valueOf(newDoom));
try {
prop.store(new FileOutputStream("resources/bot.properties"), null);
} catch (IOException e) {
e.printStackTrace();
}
return generateDoomEmbed();
}
}

private EmbedBuilder generateInvalidDoomEmbed() {
return new EmbedBuilder()
.setTitle("Not enough doom points!");
}

}

0 comments on commit 6b9c16b

Please sign in to comment.