Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-16 21:10:30 +01:00
Improve Javadoc and the GameProfileRequestEvent.
Dieser Commit ist enthalten in:
Ursprung
a3c4522ca0
Commit
afb6e69388
@ -6,9 +6,24 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
* Represents an interface to register a command executor with the proxy.
|
* Represents an interface to register a command executor with the proxy.
|
||||||
*/
|
*/
|
||||||
public interface CommandManager {
|
public interface CommandManager {
|
||||||
|
/**
|
||||||
|
* Registers the specified command with the manager with the specified aliases.
|
||||||
|
* @param command the command to register
|
||||||
|
* @param aliases the alias to use
|
||||||
|
*/
|
||||||
void register(@NonNull Command command, String... aliases);
|
void register(@NonNull Command command, String... aliases);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unregisters a command.
|
||||||
|
* @param alias the command alias to unregister
|
||||||
|
*/
|
||||||
void unregister(@NonNull String alias);
|
void unregister(@NonNull String alias);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to execute a command from the specified {@code cmdLine}.
|
||||||
|
* @param source the command's source
|
||||||
|
* @param cmdLine the command to run
|
||||||
|
* @return true if the command was found and executed, false if it was not
|
||||||
|
*/
|
||||||
boolean execute(@NonNull CommandSource source, @NonNull String cmdLine);
|
boolean execute(@NonNull CommandSource source, @NonNull String cmdLine);
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package com.velocitypowered.api.event.connection;
|
|||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.velocitypowered.api.event.ResultedEvent;
|
import com.velocitypowered.api.event.ResultedEvent;
|
||||||
import com.velocitypowered.api.event.ResultedEvent.ComponentResult;
|
|
||||||
import com.velocitypowered.api.proxy.InboundConnection;
|
import com.velocitypowered.api.proxy.InboundConnection;
|
||||||
|
|
||||||
import net.kyori.text.Component;
|
import net.kyori.text.Component;
|
||||||
@ -57,15 +56,14 @@ public class PreLoginEvent implements ResultedEvent<PreLoginEvent.PreLoginCompon
|
|||||||
* Represents an "allowed/allowed with online mode/denied" result with a reason allowed for denial.
|
* Represents an "allowed/allowed with online mode/denied" result with a reason allowed for denial.
|
||||||
*/
|
*/
|
||||||
public static class PreLoginComponentResult extends ComponentResult {
|
public static class PreLoginComponentResult extends ComponentResult {
|
||||||
|
|
||||||
private static final PreLoginComponentResult ALLOWED = new PreLoginComponentResult((Component) null);
|
private static final PreLoginComponentResult ALLOWED = new PreLoginComponentResult((Component) null);
|
||||||
private static final PreLoginComponentResult FORCE_ONLINEMODE = new PreLoginComponentResult(true);
|
private static final PreLoginComponentResult FORCE_ONLINEMODE = new PreLoginComponentResult(true);
|
||||||
|
|
||||||
private final boolean onlineMode;
|
private final boolean onlineMode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows to enable a online mode for the player connection, when Velocity running in offline mode
|
* Allows online mode to be enabled for the player connection, if Velocity is running in offline mode.
|
||||||
* Does not have any sense if velocity running in onlineMode;
|
* @param allowedOnlineMode if true, online mode will be used for the connection
|
||||||
* @param allowedOnlineMode if true, offline uuid will be used for player connection if Velocity run in offlineMode
|
|
||||||
*/
|
*/
|
||||||
private PreLoginComponentResult(boolean allowedOnlineMode) {
|
private PreLoginComponentResult(boolean allowedOnlineMode) {
|
||||||
super(true, null);
|
super(true, null);
|
||||||
@ -91,14 +89,29 @@ public class PreLoginEvent implements ResultedEvent<PreLoginEvent.PreLoginCompon
|
|||||||
return super.toString();
|
return super.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a result indicating the connection will be allowed through the proxy.
|
||||||
|
* @return the allowed result
|
||||||
|
*/
|
||||||
public static PreLoginComponentResult allowed() {
|
public static PreLoginComponentResult allowed() {
|
||||||
return ALLOWED;
|
return ALLOWED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a result indicating the connection will be allowed through the proxy, but the connection will be
|
||||||
|
* forced to use online mode provided that the proxy is in offline mode. This acts similarly to {@link #allowed()}
|
||||||
|
* on an online-mode proxy.
|
||||||
|
* @return the result
|
||||||
|
*/
|
||||||
public static PreLoginComponentResult forceOnlineMode() {
|
public static PreLoginComponentResult forceOnlineMode() {
|
||||||
return FORCE_ONLINEMODE;
|
return FORCE_ONLINEMODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Denies the login with the specified reason.
|
||||||
|
* @param reason the reason for disallowing the connection
|
||||||
|
* @return a new result
|
||||||
|
*/
|
||||||
public static PreLoginComponentResult denied(@NonNull Component reason) {
|
public static PreLoginComponentResult denied(@NonNull Component reason) {
|
||||||
Preconditions.checkNotNull(reason, "reason");
|
Preconditions.checkNotNull(reason, "reason");
|
||||||
return new PreLoginComponentResult(reason);
|
return new PreLoginComponentResult(reason);
|
||||||
|
@ -1,23 +1,33 @@
|
|||||||
package com.velocitypowered.api.event.player.gameprofile;
|
package com.velocitypowered.api.event.player.gameprofile;
|
||||||
|
|
||||||
|
import com.velocitypowered.api.proxy.InboundConnection;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.velocitypowered.api.util.GameProfile;
|
import com.velocitypowered.api.util.GameProfile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This event is fired after the {@link com.velocitypowered.api.event.connection.PreLoginEvent} in order to set up the
|
||||||
|
* game profile for the user. This can be used to configure a custom profile for a user, i.e. skin replacement.
|
||||||
|
*/
|
||||||
public class GameProfileRequestEvent {
|
public class GameProfileRequestEvent {
|
||||||
private final String username;
|
private final String username;
|
||||||
|
private final InboundConnection connection;
|
||||||
private final GameProfile originalProfile;
|
private final GameProfile originalProfile;
|
||||||
private final boolean onlineMode;
|
private final boolean onlineMode;
|
||||||
private GameProfile gameProfile;
|
private GameProfile gameProfile;
|
||||||
|
|
||||||
public GameProfileRequestEvent(GameProfile originalProfile, boolean onlinemode) {
|
public GameProfileRequestEvent(InboundConnection connection, GameProfile originalProfile, boolean onlinemode) {
|
||||||
|
this.connection = connection;
|
||||||
this.originalProfile = Preconditions.checkNotNull(originalProfile, "profile");
|
this.originalProfile = Preconditions.checkNotNull(originalProfile, "profile");
|
||||||
this.username = originalProfile.getName();
|
this.username = originalProfile.getName();
|
||||||
this.onlineMode = onlinemode;
|
this.onlineMode = onlinemode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public InboundConnection getConnection() {
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
return username;
|
return username;
|
||||||
}
|
}
|
||||||
@ -29,15 +39,23 @@ public class GameProfileRequestEvent {
|
|||||||
public boolean isOnlineMode() {
|
public boolean isOnlineMode() {
|
||||||
return onlineMode;
|
return onlineMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Returns the game profile that will be used to initialize the connection with. Should no profile be currently
|
||||||
* @return a GameProfile, can be null
|
* specified, the one generated by the proxy (for offline mode) or retrieved from the Mojang session servers (for
|
||||||
|
* online mode).
|
||||||
|
* @return the user's {@link GameProfile}
|
||||||
*/
|
*/
|
||||||
public GameProfile getGameProfile() {
|
public GameProfile getGameProfile() {
|
||||||
return gameProfile;
|
return gameProfile == null ? originalProfile : gameProfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the game profile to use for this connection. Using this method on an online-mode connection is invalid.
|
||||||
|
* @param gameProfile the profile to use for the connection, {@code null} uses the original profile
|
||||||
|
*/
|
||||||
public void setGameProfile(@Nullable GameProfile gameProfile) {
|
public void setGameProfile(@Nullable GameProfile gameProfile) {
|
||||||
|
Preconditions.checkState(!onlineMode, "Connection is in online mode, profiles can not be faked");
|
||||||
this.gameProfile = gameProfile;
|
this.gameProfile = gameProfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,8 +160,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initializePlayer(GameProfile profile, boolean onlineMode) {
|
private void initializePlayer(GameProfile profile, boolean onlineMode) {
|
||||||
|
GameProfileRequestEvent profileRequestEvent = new GameProfileRequestEvent(apiInbound, profile, onlineMode);
|
||||||
GameProfileRequestEvent profileRequestEvent = new GameProfileRequestEvent(profile, onlineMode);
|
|
||||||
|
|
||||||
VelocityServer.getServer().getEventManager().fire(profileRequestEvent).thenCompose(profileEvent -> {
|
VelocityServer.getServer().getEventManager().fire(profileRequestEvent).thenCompose(profileEvent -> {
|
||||||
// Initiate a regular connection and move over to it.
|
// Initiate a regular connection and move over to it.
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren