Skip to content

Commit

Permalink
Further cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: BT (calcastor/mame) <[email protected]>
  • Loading branch information
calcastor committed Dec 3, 2024
1 parent 800d4a5 commit 40b4364
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 53 deletions.
59 changes: 59 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
<artifactId>jdom2</artifactId>
<version>2.0.6.1</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>22.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -85,6 +91,59 @@
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.2.1</version>
<dependencies>
<dependency>
<groupId>de.skuzzle.enforcer</groupId>
<artifactId>restrict-imports-enforcer-rule</artifactId>
<version>2.1.0</version>
</dependency>
</dependencies>
<executions>
<!-- Make sure people are compiling against the correct JDK -->
<execution>
<id>enforce-jdk</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireJavaVersion>
<!-- Fuzzy match -->
<version>[${maven.compiler.target},)</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
<!-- Make sure people do not import restricted classes -->
<execution>
<id>enforce-imports</id>
<phase>process-sources</phase>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<RestrictImports>
<reason>Use org.jetbrains.annotations to add annotations</reason>
<bannedImport>javax.annotation.**</bannedImport>
</RestrictImports>
<RestrictImports>
<reason>Use tc.oc.pgm.util.Assert to add assertions</reason>
<bannedImports>
<bannedImport>com.google.common.base.Preconditions.**</bannedImport>
<bannedImport>java.util.Objects.requireNonNull</bannedImport>
</bannedImports>
</RestrictImports>
</rules>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.List;
import java.util.Optional;
import java.util.Random;
import javax.annotation.Nullable;
import org.jetbrains.annotations.Nullable;

public class VetoController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import dev.pgm.events.format.rounds.veto.settings.VetoOption;
import dev.pgm.events.format.rounds.veto.settings.VetoSettings;
import dev.pgm.events.team.TournamentTeam;
import javax.annotation.Nullable;
import org.jetbrains.annotations.Nullable;

public class VetoHistory {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
package dev.pgm.events.format.shutdown;

import static net.kyori.adventure.key.Key.key;
import static net.kyori.adventure.text.Component.text;

import dev.pgm.events.utils.TimeFormatter;
import java.time.Duration;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.countdowns.MatchCountdown;
import tc.oc.pgm.util.bukkit.Sounds;

public class ShutdownCountdown extends MatchCountdown {

protected static final Sound COUNT_SOUND =
Sound.sound(key("note.pling"), Sound.Source.MASTER, 1f, 1.19f);

public ShutdownCountdown(Match match) {
super(match);
}
Expand All @@ -25,7 +20,7 @@ public ShutdownCountdown(Match match) {
public void onTick(Duration remaining, Duration total) {
super.onTick(remaining, total);
if (remaining.getSeconds() >= 1 && remaining.getSeconds() <= 3)
getMatch().playSound(COUNT_SOUND);
getMatch().playSound(Sounds.MATCH_COUNTDOWN);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/pgm/events/ready/ReadyManager.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.pgm.events.ready;

import dev.pgm.events.utils.Response;
import javax.annotation.Nullable;
import org.jetbrains.annotations.Nullable;
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.api.party.Party;
import tc.oc.pgm.api.player.MatchPlayer;
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/dev/pgm/events/ready/ReadyManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import dev.pgm.events.utils.JoinUtils;
import dev.pgm.events.utils.Response;
import java.time.Duration;
import javax.annotation.Nullable;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;
import org.jetbrains.annotations.Nullable;
import tc.oc.pgm.api.match.Match;
import tc.oc.pgm.api.match.MatchPhase;
import tc.oc.pgm.api.party.Party;
Expand Down Expand Up @@ -41,10 +41,9 @@ public void createMatchStart(Match match, Duration duration) {
public void ready(Party party, @Nullable MatchPlayer player) {
Match match = party.getMatch();

TextComponent.Builder message =
text()
.append(party.getName())
.append(text(" marked as ").append(text("ready", NamedTextColor.GREEN)));
TextComponent.Builder message = text()
.append(party.getName())
.append(text(" marked as ").append(text("ready", NamedTextColor.GREEN)));
if (player != null) message.append(text(" by ").append(player.getName(NameStyle.COLOR)));

match.sendMessage(message);
Expand All @@ -59,10 +58,9 @@ public void ready(Party party, @Nullable MatchPlayer player) {
public void unready(Party party, @Nullable MatchPlayer player) {
Match match = party.getMatch();

TextComponent.Builder message =
text()
.append(party.getName())
.append(text(" marked as ").append(text("unready", NamedTextColor.RED)));
TextComponent.Builder message = text()
.append(party.getName())
.append(text(" marked as ").append(text("unready", NamedTextColor.RED)));
if (player != null) message.append(text(" by ").append(player.getName(NameStyle.COLOR)));

match.sendMessage(message);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/pgm/events/ready/ReadySystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.sql.Timestamp;
import java.time.Duration;
import java.time.Instant;
import javax.annotation.Nullable;
import org.jetbrains.annotations.Nullable;

public class ReadySystem {

Expand Down
25 changes: 11 additions & 14 deletions src/main/java/dev/pgm/events/team/DefaultTeamManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import javax.annotation.Nullable;
import org.bukkit.ChatColor;
import org.jetbrains.annotations.Nullable;
import tc.oc.pgm.api.party.Competitor;
import tc.oc.pgm.api.party.Party;
import tc.oc.pgm.api.player.MatchPlayer;
Expand Down Expand Up @@ -120,10 +120,8 @@ private TeamSetup getTeamSetup() {
public void syncTeams() {
List<MatchPlayer> unassigned = new ArrayList<>();

teams.forEach(
eventsTeam ->
fromTournamentTeam(eventsTeam)
.ifPresent(pgmTeam -> syncTeam(eventsTeam, pgmTeam, unassigned)));
teams.forEach(eventsTeam -> fromTournamentTeam(eventsTeam)
.ifPresent(pgmTeam -> syncTeam(eventsTeam, pgmTeam, unassigned)));

syncObserverPlayers(unassigned);
}
Expand All @@ -141,15 +139,14 @@ private void syncTeam(TournamentTeam eventsTeam, Team pgmTeam, List<MatchPlayer>
}

// Move other players to the team (from obs or other teams)
toAssign.forEach(
tournamentPlayer -> {
MatchPlayer player = pgmTeam.getMatch().getPlayer(tournamentPlayer.getUUID());
if (player != null && JoinUtils.canJoin(player.getId(), pgmTeam).isAllowed()) {
if (syncPlayer(player, pgmTeam, joinRequest)) {
unassigned.remove(player);
}
}
});
toAssign.forEach(tournamentPlayer -> {
MatchPlayer player = pgmTeam.getMatch().getPlayer(tournamentPlayer.getUUID());
if (player != null && JoinUtils.canJoin(player.getId(), pgmTeam).isAllowed()) {
if (syncPlayer(player, pgmTeam, joinRequest)) {
unassigned.remove(player);
}
}
});
}

private void syncObserverPlayers(List<MatchPlayer> unassigned) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/pgm/events/utils/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import static net.kyori.adventure.text.Component.text;

import javax.annotation.Nullable;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.Nullable;

public class Response {

Expand Down
30 changes: 12 additions & 18 deletions src/main/java/dev/pgm/events/xml/RoundParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,15 @@
public class RoundParser {

public static TournamentRound parse(TournamentFormat format, Element round) {
switch (round.getName().toLowerCase()) {
case "match":
return SingleParser.parse(format, round);
case "veto":
return VetoParser.parse(format, round);
case "result-from":
return ResultFromParser.parse(format, round);
case "format":
return FormatParser.parse(format, round);
case "veto-selector":
return new VetoSelectorRound(format, new VetoSelectorSettings());
}

throw new IllegalArgumentException("Round " + round.getName() + " is not supported!");
return switch (round.getName().toLowerCase()) {
case "match" -> SingleParser.parse(format, round);
case "veto" -> VetoParser.parse(format, round);
case "result-from" -> ResultFromParser.parse(format, round);
case "format" -> FormatParser.parse(format, round);
case "veto-selector" -> new VetoSelectorRound(format, new VetoSelectorSettings());
default -> throw new IllegalArgumentException(
"Round " + round.getName() + " is not supported!");
};
}

public static class SingleParser {
Expand Down Expand Up @@ -118,10 +113,9 @@ private static VetoSettings.Veto parseVeto(Element element) {
if (insert.equalsIgnoreCase("back")) type = VetoSettings.VetoType.CHOOSE_LAST;
else if (insert.equalsIgnoreCase("front")) type = VetoSettings.VetoType.CHOOSE_FIRST;
else
throw new IllegalArgumentException(
"Invalid insert position "
+ insert
+ ". Valid positions are back (default) or front.");
throw new IllegalArgumentException("Invalid insert position "
+ insert
+ ". Valid positions are back (default) or front.");
}

if (type == null)
Expand Down

0 comments on commit 40b4364

Please sign in to comment.