diff --git a/2006Scape Server/src/main/java/com/rs2/GameEngine.java b/2006Scape Server/src/main/java/com/rs2/GameEngine.java index 8623004a..0af36aea 100644 --- a/2006Scape Server/src/main/java/com/rs2/GameEngine.java +++ b/2006Scape Server/src/main/java/com/rs2/GameEngine.java @@ -38,8 +38,6 @@ import com.rs2.integrations.PlayersOnlineWebsite; import com.rs2.integrations.RegisteredAccsWebsite; import com.rs2.integrations.discord.DiscordActivity; import com.rs2.integrations.discord.JavaCord; -import com.rs2.tick.Scheduler; -import com.rs2.tick.Tick; import com.rs2.util.HostBlacklist; import com.rs2.world.GlobalDropsHandler; import com.rs2.world.ItemHandler; @@ -93,18 +91,6 @@ public class GameEngine { return d; } - private static final Scheduler scheduler2 = new Scheduler(); - - - public static Scheduler getScheduler() { - return scheduler2; - } - - public static void schedule(Tick tick) { - getScheduler().schedule(tick); - } - - public static String ersSecret; public static int[] cannonsX = new int[50]; public static int[] cannonsY = new int[50]; diff --git a/2006Scape Server/src/main/java/com/rs2/game/content/skills/farming/FarmingTask.java b/2006Scape Server/src/main/java/com/rs2/game/content/skills/farming/FarmingTask.java index 7fa44f47..d1260272 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/content/skills/farming/FarmingTask.java +++ b/2006Scape Server/src/main/java/com/rs2/game/content/skills/farming/FarmingTask.java @@ -1,19 +1,23 @@ package com.rs2.game.content.skills.farming; +import com.rs2.event.CycleEvent; +import com.rs2.event.CycleEventContainer; import com.rs2.game.players.Player; -import com.rs2.tick.Tick; -public class FarmingTask extends Tick { - - private Player player; +public class FarmingTask extends CycleEventContainer { public FarmingTask(Player player) { - super(10); - this.player = player; - } + super("farming task".hashCode(), player, new CycleEvent() { - @Override - protected void execute() { - Farming.processCalc(player); + @Override + public void execute(CycleEventContainer container) { + Farming.processCalc(player); + } + + @Override + public void stop() { + } + + }, 10); } } \ No newline at end of file diff --git a/2006Scape Server/src/main/java/com/rs2/tick/Scheduler.java b/2006Scape Server/src/main/java/com/rs2/tick/Scheduler.java deleted file mode 100644 index 4d6bdc89..00000000 --- a/2006Scape Server/src/main/java/com/rs2/tick/Scheduler.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.rs2.tick; - -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Queue; - -/** - * A class which schedules the execution of {@link Tick}s. - * - * @author Graham - */ -public final class Scheduler { - - /** - * A list of active ticks. - */ - private final List ticks = new ArrayList(); - - /** - * A queue of ticks that still need to be added. - */ - private final Queue newTicks = new ArrayDeque(); - - /** - * Schedules the specified tick. - * - * @param tick - * The tick to schedule. - */ - public void schedule(final Tick tick) { - synchronized (newTicks) { - newTicks.add(tick); - } - } - - /** - * This method is called every cycle and executes, adds and removes - * {@link Tick}s. - */ - public void process() { - synchronized (newTicks) { - Tick tick; - while ((tick = newTicks.poll()) != null) - ticks.add(tick); - } - - for (Iterator it = ticks.iterator(); it.hasNext();) { - Tick tick = it.next(); - try { - if (!tick.tick()) - it.remove(); - } catch (Throwable t) { - t.printStackTrace(); - } - } - } -} \ No newline at end of file diff --git a/2006Scape Server/src/main/java/com/rs2/tick/Tick.java b/2006Scape Server/src/main/java/com/rs2/tick/Tick.java deleted file mode 100644 index 79249ed3..00000000 --- a/2006Scape Server/src/main/java/com/rs2/tick/Tick.java +++ /dev/null @@ -1,151 +0,0 @@ -package com.rs2.tick; - -/** - * Represents a periodic task that can be scheduled with a {@link Scheduler}. - * - * @author Graham - */ -public abstract class Tick { - - /** - * The number of cycles between consecutive executions of this task. - */ - private final int delay; - - /** - * The current 'count down' value. When this reaches zero the task will be - * executed. - */ - private int countdown; - - /** - * A flag which indicates if this task is still running. - */ - private boolean running = true; - - /** - * Creates a new task with the specified delay. - * - * @param delay - * The number of cycles between consecutive executions of this - * task. - * @throws IllegalArgumentException - * if the {@code delay} is not positive. - */ - public Tick(int delay) { - checkDelay(delay); - this.delay = delay; - this.countdown = delay; - } - - /** - * Checks if the task is running. - * - * @return {@code true} if so, {@code false} if not. - */ - public boolean isRunning() { - return running; - } - - /** - * Checks if the task is stopped. - * - * @return {@code true} if so, {@code false} if not. - */ - public boolean isStopped() { - return !running; - } - - /** - * This method should be called by the scheduling class every cycle. It - * updates the {@link #countdown} and calls the {@link #execute()} method if - * necessary. - * - * @return A flag indicating if the task is running. - */ - public boolean tick() { - if (running && --countdown == 0) { - execute(); - countdown = delay; - } - return running; - } - - public int getCountdown() { - return countdown; - } - - /** - * Performs this task's action. - */ - protected abstract void execute(); - - /** - * Changes the delay of this task. - * - * @param delay - * The number of cycles between consecutive executions of this - * task. - * @throws IllegalArgumentException - * if the {@code delay} is not positive. - */ - public void setDelay(int delay) { - checkDelay(delay); - delay = 0; - } - - /** - * Stops this task. - * - * @throws IllegalStateException - * if the task has already been stopped. - */ - public void stop() { - if (!checkStopped()) - return; - running = false; - onStop(); - } - - /** - * Stops this task. Does not run the onStop method. - * - * @throws IllegalStateException - * if the task has already been stopped. - */ - public void forceStop() { - checkStopped(); - running = false; - } - - /** - * Override this method for code which should be run when the task stops. - */ - public void onStop() { - - } - - /** - * Checks if the delay is negative and throws an exception if so. - * - * @param delay - * The delay. - * @throws IllegalArgumentException - * if the delay is not positive. - */ - private void checkDelay(int delay) { - if (delay < 0) - throw new IllegalArgumentException("Delay must be positive."); - } - - /** - * Checks if this task has been stopped and throws an exception if so. - * - * @throws IllegalStateException - * if the task has been stopped. - */ - private boolean checkStopped() { - return running; - } - -} \ No newline at end of file