Skip to content

Commit

Permalink
Merge pull request #3 from FrostHexABG/2-fix-indexoutofbounds
Browse files Browse the repository at this point in the history
Catch IndexOutofBoundsException created when a player attempts to pitstop before starting any laps in a race
  • Loading branch information
JustBru00 authored Sep 2, 2024
2 parents 4ecde77 + 31930ca commit 4a648c3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.pigalala</groupId>
<artifactId>PigStops</artifactId>
<version>2.4.0</version>
<version>2.4.1</version>
<packaging>jar</packaging>

<name>PigStops</name>
Expand Down Expand Up @@ -81,9 +81,9 @@

<dependencies>
<dependency>
<groupId>com.github.Makkuusen</groupId>
<groupId>com.github.FrostHexABG</groupId>
<artifactId>TimingSystem</artifactId>
<version>2.0.3</version>
<version>2.2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/me/pigalala/pigstops/OinkListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.destroystokyo.paper.event.player.PlayerStopSpectatingEntityEvent;
import me.makkuusen.timing.system.api.TimingSystemAPI;
import me.makkuusen.timing.system.heat.Lap;
import me.pigalala.pigstops.pit.management.pitmodes.Pit;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
Expand Down Expand Up @@ -56,8 +57,20 @@ public void onMove(PlayerMoveEvent e) {
PigStops.getPlugin().getLogger().log(Level.SEVERE, "The default pit game has not been set. PigStops will not work correctly until a default pit game is set.");
e.getPlayer().sendMessage(Component.text().append(Component.text("The PigStop did not work as the default pit game is not set. Please ask an administrator to set the default pit game.", NamedTextColor.RED)));
} else {
if(driver.get().getHeat().isActive() && driver.get().getCurrentLap() != null && !driver.get().getCurrentLap().isPitted()) pp.newPit(Pit.Type.REAL);
}
// Issue #2 - Catch IndexOutofBoundException that appears when a player hasn't started a lap at all yet.
Lap lap = null;

try {
lap = driver.get().getCurrentLap();
} catch (IndexOutOfBoundsException ex) {
PigStops.getPlugin().getLogger().log(Level.WARNING, "Getting driver " + driver.get().getTPlayer().getNameDisplay() + "'s current lap caused an IndexOutOfBoundsException. Have they started a lap yet?");
return;
}

if (driver.get().getHeat().isActive() && lap != null && !lap.isPitted()) {
pp.newPit(Pit.Type.REAL);
}
}
}

@EventHandler
Expand Down

0 comments on commit 4a648c3

Please sign in to comment.