Skip to content

Commit

Permalink
Merge pull request #3 from asiddiqi18/dev
Browse files Browse the repository at this point in the history
Version 1.13
  • Loading branch information
asiddiqi18 authored May 13, 2022
2 parents 9b80881 + 06fa168 commit fe6e6d7
Show file tree
Hide file tree
Showing 30 changed files with 197 additions and 354 deletions.
2 changes: 1 addition & 1 deletion .idea/artifacts/trivia_jar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

113 changes: 0 additions & 113 deletions dependency-reduced-pom.xml

This file was deleted.

5 changes: 2 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.marcarrots</groupId>
<artifactId>trivia</artifactId>
<version>1.12</version>
<version>1.13</version>
<packaging>jar</packaging>

<name>Trivia</name>
Expand Down Expand Up @@ -37,7 +37,6 @@
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<!-- Replace this with your package! -->
<shadedPattern>me.marcarrots.trivia</shadedPattern>
</relocation>
</relocations>
Expand Down Expand Up @@ -98,7 +97,7 @@
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>2.2.1</version>
<version>3.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/me/marcarrots/trivia/AutomatedGameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public long getNextAutomatedTimeFromNow() {
}



private void setNextAutomatedTimeEpoch() {
nextAutomatedTimeEpoch = System.currentTimeMillis() + ((long) automatedTimeMinutes * 60 * 1000);
}
Expand All @@ -56,7 +55,7 @@ public void automatedSchedule() {
schedulerTask = trivia.getServer().getScheduler().scheduleSyncRepeatingTask(trivia, () -> {
int onlinePlayerCount = Bukkit.getOnlinePlayers().size();
if (onlinePlayerCount < automatedPlayerReq) {
Bukkit.getLogger().info(String.format("Automated Trivia Canceled (%s players online, needed %s)...",onlinePlayerCount, automatedPlayerReq));
Bukkit.getLogger().info(String.format("Automated Trivia Canceled (%s players online, needed %s)...", onlinePlayerCount, automatedPlayerReq));
setNextAutomatedTimeEpoch();
return;
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/me/marcarrots/trivia/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public class Game {
private final double similarityScore;
private final boolean bossBarEnabled;
private final int timeBetween;
private long timePerQuestion;
private int amountOfRounds;
private boolean doRepetition;
private CommandSender commandSender;
private final long timePerQuestion;
private final int amountOfRounds;
private final boolean doRepetition;
private final CommandSender commandSender;
private long roundTimeStart;
private PlayerScoreHolder scores;
private Question currentQuestion;
Expand Down Expand Up @@ -140,7 +140,7 @@ private void handleRoundOutcome() {
));
if (roundWinner != null) {
Effects.playSound(roundWinner, trivia.getConfig(), "Answer correct sound", "Answer correct pitch");
scores.addScore(roundWinner);
scores.addScore(roundWinner, getQuestionNum());
trivia.getRewards()[0].giveReward(roundWinner);
roundWinner = null;
}
Expand Down
73 changes: 0 additions & 73 deletions src/main/java/me/marcarrots/trivia/ImportQuestions.java

This file was deleted.

18 changes: 16 additions & 2 deletions src/main/java/me/marcarrots/trivia/PlayerScore.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@ public class PlayerScore implements Comparable<PlayerScore> {

private Player player;
private int points;
private int roundLastScored;

public PlayerScore(Player player) {
this.player = player;
points = 0;
roundLastScored = 0;
}

public void incrementScore() {
public int getRoundLastScored() {
return roundLastScored;
}

public void incrementScore(int round) {
roundLastScored = round;
points++;
}

Expand All @@ -28,8 +35,15 @@ public int getPoints() {
return points;
}

// returning 0 -> object considered greater
// determined by points first, if points are equal, then compares who got to those points first
@Override
public int compareTo(PlayerScore o) {
return Integer.compare(o.getPoints(), this.getPoints());
int scoreCompare = Integer.compare(o.getPoints(), this.getPoints()); // returns greater than 0 if other is greater
if (scoreCompare == 0) {
return Integer.compare(this.getRoundLastScored(), o.getRoundLastScored()); // returns greater than 0 if other is less
} else {
return scoreCompare;
}
}
}
9 changes: 3 additions & 6 deletions src/main/java/me/marcarrots/trivia/PlayerScoreHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public void addPlayerToGame(Player player) {
}
}

public void addScore(Player player) {
public void addScore(Player player, int round) {
PlayerScore score = scores.get(player.getName());
score.incrementScore();
score.incrementScore(round);
scores.put(player.getName(), score);
}

Expand All @@ -45,6 +45,7 @@ public void broadcastLargestScores() {

String[] message = Lang.TRIVIA_WINNER_MESSAGE.format_multiple(new Placeholder.PlaceholderBuilder().build());
List<String> winnerList = new ArrayList<>();

if (scoreValues.size() == 0 || scoreValues.get(0).getPoints() == 0) {
Lang.broadcastMessage(Lang.TRIVIA_NO_WINNERS.format_multiple(null));
return;
Expand All @@ -64,10 +65,6 @@ public void broadcastLargestScores() {
.build()
));

if (trivia.getConfig().getBoolean("Summon fireworks", true)) {
Effects.summonFireWork(player);
}

if (i < 3) {
rewards[i + 1].giveReward(player);
}
Expand Down
Loading

0 comments on commit fe6e6d7

Please sign in to comment.