Skip to content

Commit 7e4d7de

Browse files
committed
Expose few multi threaded world aware APIs
1 parent 576aaf1 commit 7e4d7de

File tree

1 file changed

+36
-0
lines changed
  • src/main/java/org/spongepowered/api/world

1 file changed

+36
-0
lines changed

src/main/java/org/spongepowered/api/world/World.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
import org.spongepowered.api.effect.Viewer;
3030
import org.spongepowered.api.entity.Entity;
3131
import org.spongepowered.api.entity.living.player.Player;
32+
import org.spongepowered.api.event.CauseStackManager;
3233
import org.spongepowered.api.registry.RegistryHolder;
34+
import org.spongepowered.api.scheduler.Scheduler;
3335
import org.spongepowered.api.service.context.ContextSource;
3436
import org.spongepowered.api.util.annotation.DoNotStore;
3537
import org.spongepowered.api.world.chunk.WorldChunk;
@@ -227,4 +229,38 @@ default Optional<WorldChunk> loadChunk(final Vector3i chunkPosition, final boole
227229
*/
228230
Iterable<WorldChunk> loadedChunks();
229231

232+
/**
233+
* Gets the {@link Scheduler} used to schedule sync tasks on this {@link World}.
234+
*
235+
* <p><strong>Note:</strong> Accessing objects outside of this {@link World}
236+
* from the scheduled tasks can lead to hard to diagnose problems
237+
* or unrecoverable crashes.</p>
238+
*
239+
* @return The sync scheduler
240+
*/
241+
default Scheduler scheduler() {
242+
return this.engine().scheduler();
243+
}
244+
245+
/**
246+
* Gets the {@link CauseStackManager} for handling the current event cause
247+
* stack and context information.
248+
*
249+
* <p><strong>Note:</strong> Accessing this outside of {@link World#onWorldThread()}
250+
* can lead to hard to diagnose problems or unrecoverable crashes.</p>
251+
*
252+
* @return The cause stack manager
253+
*/
254+
default CauseStackManager causeStackManager() {
255+
return this.engine().causeStackManager();
256+
}
257+
258+
/**
259+
* Checks if the {@link Thread#currentThread() current thread} is the main thread of the world.
260+
*
261+
* @return {@code true} if main thread, {@code false} if not
262+
*/
263+
default boolean onWorldThread() {
264+
return this.engine().onMainThread();
265+
}
230266
}

0 commit comments

Comments
 (0)