mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-30 21:17:53 +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
|
||||
*/
|
||||
default @NotNull Optional<T> local() {
|
||||
if (Thread.currentThread() == getHandler().getTickThread())
|
||||
return Optional.of(unwrap());
|
||||
if (isLocal()) return Optional.of(unwrap());
|
||||
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.
|
||||
* <p>
|
||||
|
Loading…
Reference in New Issue
Block a user