mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-01 05:58:00 +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() {
|
||||
var optional = local();
|
||||
if (optional.isPresent()) {
|
||||
return Acquired.local(optional.get());
|
||||
} else {
|
||||
final Thread currentThread = Thread.currentThread();
|
||||
final TickThread tickThread = getHandler().getTickThread();
|
||||
return Acquired.locked(unwrap(), currentThread, tickThread);
|
||||
}
|
||||
return optional.map(Acquired::local).orElseGet(() -> Acquired.locked(this));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,8 +19,10 @@ public class Acquired<T> {
|
||||
return new Acquired<>(value, false, null, null);
|
||||
}
|
||||
|
||||
protected static <T> Acquired<T> locked(@NotNull T value, Thread currentThread, TickThread tickThread) {
|
||||
return new Acquired<>(value, true, currentThread, tickThread);
|
||||
protected static <T> Acquired<T> locked(@NotNull Acquirable<T> acquirable) {
|
||||
final Thread currentThread = Thread.currentThread();
|
||||
final TickThread tickThread = acquirable.getHandler().getTickThread();
|
||||
return new Acquired<>(acquirable.unwrap(), true, currentThread, tickThread);
|
||||
}
|
||||
|
||||
private Acquired(@NotNull T value,
|
||||
|
Loading…
Reference in New Issue
Block a user