Skip to content

Commit

Permalink
Fix attack tasks not being cancelled correctly. (#335)
Browse files Browse the repository at this point in the history
* Fix attack tasks not being cancelled correctly.

* Happier with javadocs.
  • Loading branch information
LlmDl authored Jan 15, 2024
1 parent a502ea4 commit 1b94005
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ If a change is missing, it is likely simple or was forgotten about when this log
Feel free to PR corrections to this file.

<!-- ## [Unreleased][Unreleased]-->
## [0.6.2][0.6.2]

### Added

* None.

### Changed

* None.

### Fixed

- Fix attacks tasks not being cancelled correctly.

### Removed

- None

## [0.6.1][0.6.1]

### Added
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>io.github.townyadvanced.flagwar</groupId>
<artifactId>FlagWar</artifactId>
<packaging>jar</packaging>
<version>0.6.1</version>
<version>0.6.2</version>
<description>An OG war system for TownyAdvanced. Celebrating a decade of Flag-based Towny Warfare.</description>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
import com.gmail.filoghost.holographicdisplays.api.line.TextLine;
import com.palmergames.bukkit.towny.object.Coord;
import com.palmergames.bukkit.towny.scheduling.ScheduledTask;
import com.palmergames.bukkit.towny.scheduling.TaskScheduler;

import io.github.townyadvanced.flagwar.CellAttackThread;
Expand Down Expand Up @@ -69,8 +70,12 @@ public class CellUnderAttack extends Cell {
private int flagPhaseID;
/** A thread used to update the state of the {@link CellUnderAttack} using the Scheduler's repeating task.*/
private CellAttackThread thread;
/** A task used to the thread used to cancel the repeating task.*/
private ScheduledTask threadTask;
/** A thread used to update the {@link #hologram}'s {@link #timerLine}. */
private HologramUpdateThread hologramThread;
/** A task used to the hologramThread used to cancel the repeating task.*/
private ScheduledTask hologramTask;
/** Holds the war flag hologram. */
private Hologram hologram;
/** Holds the time, in seconds, assuming 20 ticks is 1 second, of the war flag. */
Expand Down Expand Up @@ -361,11 +366,11 @@ public void beginAttack() {
final int tps = 20;
final int milliTicks = 50;
final long ticksFromMs = this.flagPhaseDuration.toMillis() / milliTicks;
scheduler.runRepeating(() -> thread.run(), ticksFromMs, ticksFromMs);
threadTask = scheduler.runRepeating(() -> thread.run(), ticksFromMs, ticksFromMs);
if (FlagWarConfig.isHologramEnabled()) {
drawHologram();
if (FlagWarConfig.hasTimerLine()) {
scheduler.runRepeating(() -> hologramThread.run(), tps, tps);
hologramTask = scheduler.runRepeating(() -> hologramThread.run(), tps, tps);
}
}
}
Expand All @@ -376,11 +381,11 @@ public void beginAttack() {
* exists, using {@link #destroyHologram()}.
*/
public void cancel() {
if (thread != null) {
thread.cancel();
if (threadTask != null) {
threadTask.cancel();
}
if (FlagWarConfig.isHologramEnabled() && hologramThread != null) {
hologramThread.cancel();
if (FlagWarConfig.isHologramEnabled() && hologramTask != null) {
hologramTask.cancel();
}
destroyFlag();
if (hologram != null) {
Expand Down

0 comments on commit 1b94005

Please sign in to comment.