mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-12-29 12:37:40 +01:00
Fix obtaining UserCapability on Forge for respawned players
This commit is contained in:
parent
1bfbd27701
commit
ce6031ad52
@ -36,6 +36,7 @@ import net.luckperms.api.query.QueryOptions;
|
||||
import net.luckperms.api.util.Tristate;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.common.util.LazyOptional;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -44,6 +45,19 @@ import java.util.Locale;
|
||||
|
||||
public class UserCapabilityImpl implements UserCapability {
|
||||
|
||||
private static LazyOptional<UserCapability> getCapability(Player player) {
|
||||
if (!player.isRemoved()) {
|
||||
return player.getCapability(CAPABILITY);
|
||||
} else {
|
||||
player.reviveCaps();
|
||||
try {
|
||||
return player.getCapability(CAPABILITY);
|
||||
} finally {
|
||||
player.invalidateCaps();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a {@link UserCapability} for a given {@link ServerPlayer}.
|
||||
*
|
||||
@ -51,8 +65,7 @@ public class UserCapabilityImpl implements UserCapability {
|
||||
* @return the capability
|
||||
*/
|
||||
public static @NotNull UserCapabilityImpl get(@NotNull Player player) {
|
||||
return (UserCapabilityImpl) player.getCapability(CAPABILITY)
|
||||
.orElseThrow(() -> new IllegalStateException("Capability missing for " + player.getUUID()));
|
||||
return (UserCapabilityImpl) getCapability(player).orElseThrow(() -> new IllegalStateException("Capability missing for " + player.getUUID()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -62,7 +75,7 @@ public class UserCapabilityImpl implements UserCapability {
|
||||
* @return the capability, or null
|
||||
*/
|
||||
public static @Nullable UserCapabilityImpl getNullable(@NotNull Player player) {
|
||||
return (UserCapabilityImpl) player.getCapability(CAPABILITY).resolve().orElse(null);
|
||||
return (UserCapabilityImpl) getCapability(player).resolve().orElse(null);
|
||||
}
|
||||
|
||||
private boolean initialised = false;
|
||||
|
Loading…
Reference in New Issue
Block a user