Fix reflection in PlayerDataStorage + new wrapOptional method in reflection library

This commit is contained in:
2024-07-17 23:24:13 +02:00
parent e16487431d
commit fcac9af7d1
2 changed files with 26 additions and 5 deletions

View File

@@ -16,13 +16,12 @@ public class PlayerDataStorage extends ReflectWrapper {
public static final ReflectMethod<?> load = wrapEx(() -> REFLECT.method("load", String.class, String.class));
/**
* @param playerName the name of the player: used for loading error message and of offline UUID generation.
* @param playerId UUID of a player as it is used to name the player data file (UUID.toString())
* @param playerName the name of the player: used for loading error message and for offline UUID generation.
* @param playerId UUID of a player as it is used to name the player data file (UUID.toString()).
*/
@SuppressWarnings("unchecked")
public Optional<CompoundTag> load(String playerName, String playerId) {
return ((Optional<Object>) wrapReflectEx(() -> load.invoke(__getRuntimeInstance(), playerId)))
.map(o -> wrap(o, CompoundTag.class));
return wrapOptional((Optional<Object>) wrapReflectEx(() -> load.invoke(__getRuntimeInstance(), playerName, playerId)), CompoundTag.class);
}