Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-16 21:10:30 +01:00
Provide access to Pointer values
Dieser Commit ist enthalten in:
Ursprung
793ad443c6
Commit
f579725002
@ -94,12 +94,15 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||
import net.kyori.adventure.audience.MessageType;
|
||||
import net.kyori.adventure.bossbar.BossBar;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
import net.kyori.adventure.permission.PermissionChecker;
|
||||
import net.kyori.adventure.pointer.Pointer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
|
||||
import net.kyori.adventure.util.TriState;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
@ -122,6 +125,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
private final MinecraftConnection connection;
|
||||
private final @Nullable InetSocketAddress virtualHost;
|
||||
private GameProfile profile;
|
||||
private PermissionChecker permissionChecker;
|
||||
private PermissionFunction permissionFunction;
|
||||
private int tryIndex = 0;
|
||||
private long ping = -1;
|
||||
@ -149,6 +153,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
this.profile = profile;
|
||||
this.connection = connection;
|
||||
this.virtualHost = virtualHost;
|
||||
this.permissionChecker = PermissionChecker.always(TriState.FALSE);
|
||||
this.permissionFunction = PermissionFunction.ALWAYS_UNDEFINED;
|
||||
this.connectionPhase = connection.getType().getInitialClientPhase();
|
||||
this.knownChannels = CappedSet.create(MAX_PLUGIN_CHANNELS);
|
||||
@ -249,6 +254,18 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
|
||||
void setPermissionFunction(PermissionFunction permissionFunction) {
|
||||
this.permissionFunction = permissionFunction;
|
||||
this.permissionChecker = permission -> {
|
||||
final Tristate state = permissionFunction.getPermissionValue(permission);
|
||||
if (state == Tristate.TRUE) {
|
||||
return TriState.TRUE;
|
||||
} else if (state == Tristate.UNDEFINED) {
|
||||
return TriState.NOT_SET;
|
||||
} else if (state == Tristate.FALSE) {
|
||||
return TriState.FALSE;
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -261,6 +278,19 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
return connection.getProtocolVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked") // safe casts
|
||||
public <T> Optional<T> get(final Pointer<T> pointer) {
|
||||
if (pointer == Identity.UUID) {
|
||||
return Optional.of((T) this.getUniqueId());
|
||||
} else if (pointer == Identity.NAME) {
|
||||
return Optional.of((T) this.getGameProfile().getName());
|
||||
} else if (pointer == PermissionChecker.POINTER) {
|
||||
return Optional.of((T) this.permissionChecker);
|
||||
}
|
||||
return Player.super.get(pointer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(net.kyori.text.Component component, MessagePosition position) {
|
||||
Preconditions.checkNotNull(component, "component");
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren