mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-02 14:38:26 +01:00
Add Acquirable#isLocal
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
42f4678db0
commit
5106927b10
@ -98,11 +98,19 @@ public interface Acquirable<T> {
|
|||||||
* {@link Optional#empty()} otherwise
|
* {@link Optional#empty()} otherwise
|
||||||
*/
|
*/
|
||||||
default @NotNull Optional<T> local() {
|
default @NotNull Optional<T> local() {
|
||||||
if (Thread.currentThread() == getHandler().getTickThread())
|
if (isLocal()) return Optional.of(unwrap());
|
||||||
return Optional.of(unwrap());
|
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets if the acquirable element is local to this thread
|
||||||
|
*
|
||||||
|
* @return true if the element is linked to the current thread
|
||||||
|
*/
|
||||||
|
default boolean isLocal() {
|
||||||
|
return Thread.currentThread() == getHandler().getTickThread();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Locks the acquirable element, execute {@code consumer} synchronously and unlock the thread.
|
* Locks the acquirable element, execute {@code consumer} synchronously and unlock the thread.
|
||||||
* <p>
|
* <p>
|
||||||
|
Loading…
Reference in New Issue
Block a user