Skip to content

Commit

Permalink
Fix flag scheduler not running properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
LlmDl committed Jan 15, 2024
1 parent 168ece4 commit a81fffa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public FlagWarCustomListener(final FlagWar flagWar) {
* {@link FlagWar#registerAttack(CellUnderAttack)} using the cell from the CellAttackEvent.
* @param cellAttackEvent the associated CellAttackEvent.
*/
@EventHandler(priority = EventPriority.LOWEST)
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
@SuppressWarnings("unused")
public void onCellAttackEvent(final CellAttackEvent cellAttackEvent) {
if (cellAttackEvent.isCancelled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
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,9 +68,9 @@ public class CellUnderAttack extends Cell {
/** Identifies the phase the war flag is in. **/
private int flagPhaseID;
/** A thread used to update the state of the {@link CellUnderAttack} using the Scheduler's repeating task.*/
private ScheduledTask thread;
private CellAttackThread thread;
/** A thread used to update the {@link #hologram}'s {@link #timerLine}. */
private ScheduledTask hologramThread;
private HologramUpdateThread hologramThread;
/** 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 @@ -99,6 +98,8 @@ public CellUnderAttack(final String flagOwner, final Block base, final Duration
this.flagLightBlock = world.getBlockAt(base.getX(), base.getY() + 2, base.getZ());

this.flagPhaseDuration = timerPhase;
this.thread = new CellAttackThread(this);
this.hologramThread = new HologramUpdateThread(this);
}

/** @return if {@link CellUnderAttack} equals a given {@link Object}. (Defers to {@link Cell#equals(Object)}.) */
Expand Down Expand Up @@ -360,11 +361,11 @@ public void beginAttack() {
final int tps = 20;
final int milliTicks = 50;
final long ticksFromMs = this.flagPhaseDuration.toMillis() / milliTicks;
thread = scheduler.runRepeating(() -> new CellAttackThread(this), ticksFromMs, ticksFromMs);
scheduler.runRepeating(() -> thread.run(), ticksFromMs, ticksFromMs);
if (FlagWarConfig.isHologramEnabled()) {
drawHologram();
if (FlagWarConfig.hasTimerLine()) {
hologramThread = scheduler.runRepeating(() -> new HologramUpdateThread(this), tps, tps);
scheduler.runRepeating(() -> hologramThread.run(), tps, tps);
}
}
}
Expand Down

0 comments on commit a81fffa

Please sign in to comment.