Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to Spotless, general cleanup, and adapt to upstream PGM changes #34

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-java@v4
with:
java-version: 21
Expand Down
90 changes: 84 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
<version>1.0.0-SNAPSHOT</version>
<name>Events</name>

<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<repositories>
<repository>
<id>ashcon-repo</id>
Expand Down Expand Up @@ -35,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 All @@ -44,18 +56,31 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>21</source>
<target>21</target>
<annotationProcessorPaths>
<path>
<groupId>org.incendo</groupId>
<artifactId>cloud-annotations</artifactId>
<version>2.0.0-rc.2</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>

<!-- Validates that code is properly formatted with Google's code style -->
<plugin>
<groupId>com.coveo</groupId>
<artifactId>fmt-maven-plugin</artifactId>
<version>2.9</version>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.43.0</version>
<configuration>
<style>google</style>
<ratchetFrom>origin/master</ratchetFrom>
<java>
<removeUnusedImports/>
<palantirJavaFormat>
<version>2.47.0</version>
<style>GOOGLE</style>
<formatJavadoc>true</formatJavadoc>
</palantirJavaFormat>
</java>
</configuration>
<executions>
<execution>
Expand All @@ -66,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
Loading