9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-19 15:09:15 +00:00

Merge pull request #504 from Catnies/dev-contextholder

contextholder添加get方法
This commit is contained in:
XiaoMoMi
2025-12-15 17:23:08 +08:00
committed by GitHub

View File

@@ -63,6 +63,11 @@ public class ContextHolder {
return this;
}
@SuppressWarnings("unchecked")
public <T> T getOrNull(ContextKey<T> parameter) {
return (T) Optional.ofNullable(this.params.get(parameter)).map(Supplier::get).orElse(null);
}
@SuppressWarnings("unchecked")
public <T> T getOrThrow(ContextKey<T> parameter) {
Supplier<T> object = (Supplier<T>) this.params.get(parameter);