mirror of
https://github.com/lucko/LuckPerms.git
synced 2025-09-02 10:52:37 +02:00
Fix obtaining UserCapability on Forge for respawned players
This commit is contained in:
@@ -36,6 +36,7 @@ import net.luckperms.api.query.QueryOptions;
|
|||||||
import net.luckperms.api.util.Tristate;
|
import net.luckperms.api.util.Tristate;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraftforge.common.util.LazyOptional;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -44,6 +45,19 @@ import java.util.Locale;
|
|||||||
|
|
||||||
public class UserCapabilityImpl implements UserCapability {
|
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}.
|
* Gets a {@link UserCapability} for a given {@link ServerPlayer}.
|
||||||
*
|
*
|
||||||
@@ -51,8 +65,7 @@ public class UserCapabilityImpl implements UserCapability {
|
|||||||
* @return the capability
|
* @return the capability
|
||||||
*/
|
*/
|
||||||
public static @NotNull UserCapabilityImpl get(@NotNull Player player) {
|
public static @NotNull UserCapabilityImpl get(@NotNull Player player) {
|
||||||
return (UserCapabilityImpl) player.getCapability(CAPABILITY)
|
return (UserCapabilityImpl) getCapability(player).orElseThrow(() -> new IllegalStateException("Capability missing for " + player.getUUID()));
|
||||||
.orElseThrow(() -> new IllegalStateException("Capability missing for " + player.getUUID()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,7 +75,7 @@ public class UserCapabilityImpl implements UserCapability {
|
|||||||
* @return the capability, or null
|
* @return the capability, or null
|
||||||
*/
|
*/
|
||||||
public static @Nullable UserCapabilityImpl getNullable(@NotNull Player player) {
|
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;
|
private boolean initialised = false;
|
||||||
|
Reference in New Issue
Block a user