package com.xfestudio.xfeservermanager.core.player;
import com.xfestudio.xfeservermanager.api.command.CommandSourceKind;
import java.util.Objects;
import java.util.UUID;
/** Shared protection against peer/superior actions and unsafe offline-mode game identities. */
public final class PlayerAuthorityGuard {
public void requireMayTarget(
ActorAuthority actor, TargetAuthority target, boolean explicitOwnerOverride) {
Objects.requireNonNull(actor, "actor");
Objects.requireNonNull(target, "target");
if (actor.actorId() != null && actor.actorId().equals(target.playerId())) {
return;
}
if (target.authorityWeight() >= actor.authorityWeight()
&& !(actor.owner() && explicitOwnerOverride)) {
throw new PlayerOperationException(
"protected_target", "same-rank and higher-rank targets are protected by default");
}
}
public void requireDangerousAuthority(ActorAuthority actor) {
Objects.requireNonNull(actor, "actor");
boolean physicalConsole = actor.source() == CommandSourceKind.CONSOLE;
boolean webOwner = actor.source() == CommandSourceKind.WEB_CONSOLE && actor.owner();
if (!actor.onlineMode() && !physicalConsole && !webOwner) {
throw new PlayerOperationException(
"offline_identity_downgrade",
"dangerous operations require a web owner or physical console in offline mode");
}
}
public record ActorAuthority(
UUID actorId,
int authorityWeight,
boolean owner,
boolean onlineMode,
CommandSourceKind source) {
public ActorAuthority {
if (authorityWeight < 0) throw new IllegalArgumentException("authorityWeight must be non-negative");
Objects.requireNonNull(source, "source");
}
}
public record TargetAuthority(UUID playerId, int authorityWeight) {
public TargetAuthority {
Objects.requireNonNull(playerId, "playerId");
if (authorityWeight < 0) throw new IllegalArgumentException("authorityWeight must be non-negative");
}
}
}
package com.xfestudio.xfeservermanager.core.player;
import com.xfestudio.xfeservermanager.api.command.CommandSourceKind;
import java.util.Objects;
import java.util.UUID;
/** Shared protection against peer/superior actions and unsafe offline-mode game identities. */
public final class PlayerAuthorityGuard {
public void requireMayTarget(
ActorAuthority actor, TargetAuthority target, boolean explicitOwnerOverride) {
Objects.requireNonNull(actor, "actor");
Objects.requireNonNull(target, "target");
if (actor.actorId() != null && actor.actorId().equals(target.playerId())) {
return;
}
if (target.authorityWeight() >= actor.authorityWeight()
&& !(actor.owner() && explicitOwnerOverride)) {
throw new PlayerOperationException(
"protected_target", "same-rank and higher-rank targets are protected by default");
}
}
public void requireDangerousAuthority(ActorAuthority actor) {
Objects.requireNonNull(actor, "actor");
boolean physicalConsole = actor.source() == CommandSourceKind.CONSOLE;
boolean webOwner = actor.source() == CommandSourceKind.WEB_CONSOLE && actor.owner();
if (!actor.onlineMode() && !physicalConsole && !webOwner) {
throw new PlayerOperationException(
"offline_identity_downgrade",
"dangerous operations require a web owner or physical console in offline mode");
}
}
public record ActorAuthority(
UUID actorId,
int authorityWeight,
boolean owner,
boolean onlineMode,
CommandSourceKind source) {
public ActorAuthority {
if (authorityWeight < 0) throw new IllegalArgumentException("authorityWeight must be non-negative");
Objects.requireNonNull(source, "source");
}
}
public record TargetAuthority(UUID playerId, int authorityWeight) {
public TargetAuthority {
Objects.requireNonNull(playerId, "playerId");
if (authorityWeight < 0) throw new IllegalArgumentException("authorityWeight must be non-negative");
}
}
}