DREAMFIRE Docs ← Back to site
Loading...
Searching...
No Matches
IDreamLoop.java
Go to the documentation of this file.
1/*
2 * MIT License
3 *
4 * Copyright (c) 2025 Dreamfire Studio
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24package com.dreamfirestudios.dreamcore.DreamLoop;
25
26import com.dreamfirestudios.dreamcore.DreamCore;
27import org.bukkit.Bukkit;
28
29import java.util.UUID;
30
64public interface IDreamLoop {
65
81 UUID ReturnID();
82
92 default long StartDelay() { return 0L; }
93
103 default long LoopInterval() { return 20L; }
104
115 void Start();
116
127 void Loop();
128
138 void End();
139
156 default void CancelLoop() {
157 final int id = GetId();
158 if (id >= 0) {
159 Bukkit.getScheduler().cancelTask(id);
160 }
161 try {
162 End();
163 } finally {
164 try {
166 } catch (Throwable ignored) {
167 // Best-effort cleanup; do not propagate
168 }
169 }
170 }
171
179 void PassID(int id);
180
190 int GetId();
191}
static final LinkedHashMap< UUID, IDreamLoop > IDreamLoops
Contract for repeating loops driven by the Bukkit scheduler.
void Loop()
Called on each tick interval.
default long StartDelay()
Delay before the first Loop() call.
void End()
Called once after cancellation to release resources.
UUID ReturnID()
Unique identifier for this loop within the DreamCore registry.
default long LoopInterval()
Interval between consecutive Loop() calls.
int GetId()
Retrieves the Bukkit scheduler task ID.
default void CancelLoop()
Cancels the scheduled task, calls End(), and unregisters this loop from DreamCore....
void PassID(int id)
Internal hook used by the scheduler to assign the Bukkit task ID.
void Start()
Called once before the scheduler begins invoking Loop().