mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-03 23:17:48 +01:00
Simplify Acquirable#lock
This commit is contained in:
parent
6c3c6e1438
commit
b8b62c4ff7
@ -83,13 +83,7 @@ public interface Acquirable<T> {
|
|||||||
*/
|
*/
|
||||||
default @NotNull Acquired<T> lock() {
|
default @NotNull Acquired<T> lock() {
|
||||||
var optional = local();
|
var optional = local();
|
||||||
if (optional.isPresent()) {
|
return optional.map(Acquired::local).orElseGet(() -> Acquired.locked(this));
|
||||||
return Acquired.local(optional.get());
|
|
||||||
} else {
|
|
||||||
final Thread currentThread = Thread.currentThread();
|
|
||||||
final TickThread tickThread = getHandler().getTickThread();
|
|
||||||
return Acquired.locked(unwrap(), currentThread, tickThread);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,8 +19,10 @@ public class Acquired<T> {
|
|||||||
return new Acquired<>(value, false, null, null);
|
return new Acquired<>(value, false, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static <T> Acquired<T> locked(@NotNull T value, Thread currentThread, TickThread tickThread) {
|
protected static <T> Acquired<T> locked(@NotNull Acquirable<T> acquirable) {
|
||||||
return new Acquired<>(value, true, currentThread, tickThread);
|
final Thread currentThread = Thread.currentThread();
|
||||||
|
final TickThread tickThread = acquirable.getHandler().getTickThread();
|
||||||
|
return new Acquired<>(acquirable.unwrap(), true, currentThread, tickThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Acquired(@NotNull T value,
|
private Acquired(@NotNull T value,
|
||||||
|
Loading…
Reference in New Issue
Block a user