Skip to content

Commit

Permalink
Infer nullity annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
minus1over12 committed Jul 10, 2024
1 parent ef0b825 commit b5d25a5
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.bukkit.scoreboard.Scoreboard;
import org.geysermc.cumulus.form.SimpleForm;
import org.geysermc.floodgate.api.FloodgateApi;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;
import java.util.UUID;
Expand All @@ -23,7 +24,7 @@ public enum FloodgateIntegration {
*
* @param player the player to send the form to
*/
static void sendTeamForm(Entity player) {
static void sendTeamForm(@NotNull Entity player) {
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
if (scoreboard.getEntityTeam(player) == null &&
player.hasPermission("quadwars.player.jointeam")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class GameStateChangeEvent extends Event {
* Static method required by the API.
* @return The handler list for this event.
*/
public static HandlerList getHandlerList() {
public static @NotNull HandlerList getHandlerList() {
return HANDLER_LIST;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;

Expand All @@ -40,7 +41,7 @@ public class LobbyWorldController implements Listener {
/**
* The lobby world.
*/
private final World lobbyWorld;
private final @NotNull World lobbyWorld;
/**
* The current game state.
*/
Expand All @@ -49,14 +50,14 @@ public class LobbyWorldController implements Listener {
/**
* The plugin used for scheduling tasks.
*/
private final Plugin plugin;
private final @NotNull Plugin plugin;

/**
* Creates a lobby world control object.
*
* @param plugin the plugin to get the game state from
*/
LobbyWorldController(QuadWars plugin) {
LobbyWorldController(@NotNull QuadWars plugin) {
gameState = plugin.getGameState();
lobbyWorld = Objects.requireNonNull(
new WorldCreator(new NamespacedKey(plugin, "lobby")).generateStructures(false)
Expand All @@ -82,7 +83,7 @@ public class LobbyWorldController implements Listener {
* @param event the event that triggered this method
*/
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
public void onPlayerJoin(@NotNull PlayerJoinEvent event) {
Player player = event.getPlayer();
if (gameState == GameState.PREGAME ||
(!player.hasPermission(QuadWars.GAMEMASTER_PERMISSION) &&
Expand Down Expand Up @@ -138,7 +139,7 @@ public void onPlayerJoin(PlayerJoinEvent event) {
* @param event the event that triggered this method
*/
@EventHandler
public void onGameStateChange(GameStateChangeEvent event) {
public void onGameStateChange(@NotNull GameStateChangeEvent event) {
gameState = event.getState();
if (gameState == GameState.PREGAME) {
for (Player player : Bukkit.getOnlinePlayers()) {
Expand All @@ -156,6 +157,7 @@ public void onGameStateChange(GameStateChangeEvent event) {
*
* @return the NamespacedKey of the lobby world
*/
@NotNull
NamespacedKey getLobbyWorldKey() {
return lobbyWorld.getKey();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;

import java.awt.Color;
import java.util.Arrays;
Expand All @@ -34,8 +35,8 @@ public class LunarClientIntegration implements Listener {
* @param homeQuadrant The quadrant the player's team is in.
* @param ignoredWorldKeys The keys of the worlds to ignore.
*/
static void setWorldBorders(Entity player, double size, Quadrant homeQuadrant,
Collection<NamespacedKey> ignoredWorldKeys) {
static void setWorldBorders(@NotNull Entity player, double size, Quadrant homeQuadrant,
@NotNull Collection<NamespacedKey> ignoredWorldKeys) {
World world = player.getWorld();
if (!(world.getEnvironment().equals(World.Environment.THE_END) ||
ignoredWorldKeys.contains(world.getKey()))) {
Expand All @@ -59,8 +60,9 @@ static void setWorldBorders(Entity player, double size, Quadrant homeQuadrant,
* @param borderModule The border module to use.
* @param cancelEntry whether to cancel entry into the border.
*/
private static void makeBorder(double size, Recipients apolloPlayer, Quadrant quadrant,
World world, BorderModule borderModule, boolean cancelEntry) {
private static void makeBorder(double size, Recipients apolloPlayer, @NotNull Quadrant quadrant,
@NotNull World world, @NotNull BorderModule borderModule,
boolean cancelEntry) {
double minCorner = WorldBorderController.AXIS_BUFFER_OFFSET / world.getCoordinateScale();
double maxCorner = size + minCorner;
// https://minecraft.wiki/w/Miscellaneous_colors#World_border
Expand All @@ -80,8 +82,8 @@ private static void makeBorder(double size, Recipients apolloPlayer, Quadrant qu
* @param size The size of the world.
* @param ignoredWorldKeys The keys of the worlds to ignore.
*/
static void setGameMasterWorldBorders(Entity player, double size,
Collection<NamespacedKey> ignoredWorldKeys) {
static void setGameMasterWorldBorders(@NotNull Entity player, double size,
@NotNull Collection<NamespacedKey> ignoredWorldKeys) {
World world = player.getWorld();
if (!(world.getEnvironment().equals(World.Environment.THE_END) ||
ignoredWorldKeys.contains(world.getKey()))) {
Expand All @@ -100,7 +102,7 @@ static void setGameMasterWorldBorders(Entity player, double size,
* @param event The event that triggered this method.
*/
@EventHandler
public static void onGameStateChange(GameStateChangeEvent event) {
public static void onGameStateChange(@NotNull GameStateChangeEvent event) {
GameState state = event.getState();
Options options = Apollo.getModuleManager().getModule(ServerRuleModule.class).getOptions();
options.set(ServerRuleModule.COMPETITIVE_GAME, state.equals(GameState.BATTLE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.jetbrains.annotations.NotNull;

/**
* Controls the players in the game.
Expand Down Expand Up @@ -45,7 +46,7 @@ public class PlayerController implements Listener {
*
* @param plugin the plugin creating this controller.
*/
public PlayerController(QuadWars plugin) {
public PlayerController(@NotNull QuadWars plugin) {
killOnQuit = plugin.getConfig().getBoolean("killOnQuit");
hardcore = plugin.getConfig().getBoolean(QuadWars.HARDCORE_CONFIG_PATH);
state = plugin.getGameState();
Expand All @@ -57,7 +58,7 @@ public PlayerController(QuadWars plugin) {
* @param event The event that triggered this method.
*/
@EventHandler
public static void onGameStateChange(GameStateChangeEvent event) {
public static void onGameStateChange(@NotNull GameStateChangeEvent event) {
state = event.getState();
switch (state) {
case PREGAME, PREP -> {
Expand Down Expand Up @@ -98,7 +99,7 @@ public static void onGameStateChange(GameStateChangeEvent event) {
* @param event the event that triggered this method
*/
@EventHandler
public void onPlayerPostRespawn(PlayerPostRespawnEvent event) {
public void onPlayerPostRespawn(@NotNull PlayerPostRespawnEvent event) {
setSpectatorIfNeeded(event.getPlayer());
}

Expand All @@ -107,7 +108,7 @@ public void onPlayerPostRespawn(PlayerPostRespawnEvent event) {
* @param event the event that triggered this method
*/
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerDeath(PlayerDeathEvent event) {
public void onPlayerDeath(@NotNull PlayerDeathEvent event) {
setSpectatorIfNeeded(event.getPlayer());
}

Expand All @@ -116,7 +117,7 @@ public void onPlayerDeath(PlayerDeathEvent event) {
*
* @param player the player to set the game mode for
*/
private void setSpectatorIfNeeded(HumanEntity player) {
private void setSpectatorIfNeeded(@NotNull HumanEntity player) {
if (hardcore && (state == GameState.BATTLE || state == GameState.POST_GAME)) {
player.setGameMode(GameMode.SPECTATOR);
}
Expand All @@ -128,7 +129,7 @@ private void setSpectatorIfNeeded(HumanEntity player) {
* @param event the event that triggered this method
*/
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
public void onPlayerQuit(@NotNull PlayerQuitEvent event) {
killIfNeeded(event.getPlayer());
}

Expand All @@ -137,7 +138,7 @@ public void onPlayerQuit(PlayerQuitEvent event) {
*
* @param player the player to check
*/
private void killIfNeeded(Damageable player) {
private void killIfNeeded(@NotNull Damageable player) {
if (hardcore && killOnQuit && state == GameState.BATTLE &&
!player.hasPermission(QuadWars.GAMEMASTER_PERMISSION)) {
player.setHealth(0);
Expand All @@ -150,7 +151,7 @@ private void killIfNeeded(Damageable player) {
* @param event the event that triggered this method
*/
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
public void onPlayerJoin(@NotNull PlayerJoinEvent event) {
killIfNeeded(event.getPlayer());
}

Expand Down
9 changes: 5 additions & 4 deletions src/main/java/io/github/minus1over12/quadwars/QuadWars.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ public void saveDefaultConfig() {
* @param gameStateConfig the configuration to save
* @param errorMessage the message to log if the save fails
*/
private void saveFileConfiguration(FileConfiguration gameStateConfig, String errorMessage) {
private void saveFileConfiguration(@NotNull FileConfiguration gameStateConfig,
String errorMessage) {
try {
gameStateConfig.save(gameStateFile);
} catch (IOException e) {
Expand All @@ -192,7 +193,7 @@ GameState getGameState() {

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
@NotNull String label, @NotNull String[] args) {
@NotNull String label, @NotNull String @NotNull [] args) {
switch (command.getName().toLowerCase()) {
case SET_STATE_COMMAND -> {
if (args.length != 1) {
Expand Down Expand Up @@ -362,7 +363,7 @@ private void transitionState(@NotNull Audience sender) {
@Override
public @NotNull List<String> onTabComplete(@NotNull CommandSender sender,
@NotNull Command command, @NotNull String alias,
@NotNull String[] args) {
@NotNull String @NotNull [] args) {
switch (command.getName().toLowerCase()) {
case SET_STATE_COMMAND -> {
return args.length == 1 ?
Expand Down Expand Up @@ -409,7 +410,7 @@ private void transitionState(@NotNull Audience sender) {
* @param event the event that triggered this method
*/
@EventHandler
public void onGameStateChange(GameStateChangeEvent event) {
public void onGameStateChange(@NotNull GameStateChangeEvent event) {
gameState = event.getState();
gameStateConfig.set(GAME_STATE_PATH, gameState.toString());
saveFileConfiguration(gameStateConfig, "Could not save game state file");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -47,11 +48,11 @@ public class TeamController implements Listener {
/**
* The logger for the plugin.
*/
private final Logger logger;
private final @NotNull Logger logger;
/**
* The default world set in the config.
*/
private final World defaultWorld;
private final @NotNull World defaultWorld;
/**
* The current game state.
*/
Expand All @@ -66,7 +67,7 @@ public class TeamController implements Listener {
*
* @param plugin the plugin creating the object
*/
TeamController(QuadWars plugin) {
TeamController(@NotNull QuadWars plugin) {
gameState = plugin.getGameState();
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
logger = plugin.getLogger();
Expand Down Expand Up @@ -106,7 +107,7 @@ public class TeamController implements Listener {
* @param event The event that triggered this method.
*/
@EventHandler
public void onGameStateChange(GameStateChangeEvent event) {
public void onGameStateChange(@NotNull GameStateChangeEvent event) {
gameState = event.getState();
switch (gameState) {
case PREGAME, BATTLE, POST_GAME -> {
Expand Down Expand Up @@ -137,7 +138,7 @@ public void onGameStateChange(GameStateChangeEvent event) {
* @param event the event that triggered this method
*/
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
public void onPlayerDeath(@NotNull PlayerDeathEvent event) {
checkWinCondition(event.getEntity());
}

Expand All @@ -147,7 +148,7 @@ public void onPlayerDeath(PlayerDeathEvent event) {
* @param event the event that triggered this method
*/
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
public void onPlayerQuit(@NotNull PlayerQuitEvent event) {
checkWinCondition(event.getPlayer());
}

Expand All @@ -156,7 +157,7 @@ public void onPlayerQuit(PlayerQuitEvent event) {
*
* @param outPlayer the player that was eliminated
*/
private void checkWinCondition(OfflinePlayer outPlayer) {
private void checkWinCondition(@NotNull OfflinePlayer outPlayer) {
if (hardcore && gameState == GameState.BATTLE) {
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
Set<Team> aliveTeams = Bukkit.getOnlinePlayers().stream()
Expand Down Expand Up @@ -191,7 +192,7 @@ private void checkWinCondition(OfflinePlayer outPlayer) {
* @param entity the entity to add
* @param quadrant the team to add the entity to
*/
void addEntityToTeam(Entity entity, Quadrant quadrant) {
void addEntityToTeam(@NotNull Entity entity, @NotNull Quadrant quadrant) {
Team team = Objects.requireNonNull(
Bukkit.getScoreboardManager().getMainScoreboard().getTeam(TEAM_PREFIX + quadrant),
"Could not load a team");
Expand Down
Loading

0 comments on commit b5d25a5

Please sign in to comment.