3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00

Extract interfaces for all events.

This is in preparation for moving to event-impl-gen.
Dieser Commit ist enthalten in:
Andrew Steinborn 2021-04-17 03:50:10 -04:00
Ursprung c8519949bc
Commit 730d385f02
68 geänderte Dateien mit 1539 neuen und 809 gelöschten Zeilen

Datei anzeigen

@ -100,10 +100,6 @@ test {
useJUnitPlatform() useJUnitPlatform()
} }
test {
useJUnitPlatform()
}
publishing { publishing {
publications { publications {
mavenJava(MavenPublication) { mavenJava(MavenPublication) {

Datei anzeigen

@ -7,7 +7,7 @@
package com.velocitypowered.api.command; package com.velocitypowered.api.command;
import com.velocitypowered.api.event.command.CommandExecuteEvent; import com.velocitypowered.api.event.command.CommandExecuteEventImpl;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
/** /**
@ -81,7 +81,7 @@ public interface CommandManager {
/** /**
* Attempts to asynchronously execute a command from the given {@code cmdLine} * Attempts to asynchronously execute a command from the given {@code cmdLine}
* without firing a {@link CommandExecuteEvent}. * without firing a {@link CommandExecuteEventImpl}.
* *
* @param source the source to execute the command for * @param source the source to execute the command for
* @param cmdLine the command to run * @param cmdLine the command to run

Datei anzeigen

@ -16,60 +16,19 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* This event is fired when someone executing command. * This event is fired when someone executes a command.
*/ */
public final class CommandExecuteEvent implements ResultedEvent<CommandResult> { public interface CommandExecuteEvent extends ResultedEvent<CommandResult> {
private final CommandSource commandSource; CommandSource getCommandSource();
private final String command;
private CommandResult result;
/** /**
* Constructs a CommandExecuteEvent. * Gets the original command being executed without the first slash.
* @param commandSource the source executing the command
* @param command the command being executed without first slash
*/
public CommandExecuteEvent(CommandSource commandSource, String command) {
this.commandSource = Preconditions.checkNotNull(commandSource, "commandSource");
this.command = Preconditions.checkNotNull(command, "command");
this.result = CommandResult.allowed();
}
public CommandSource getCommandSource() {
return commandSource;
}
/**
* Gets the original command being executed without first slash.
* @return the original command being executed * @return the original command being executed
*/ */
public String getCommand() { String getCommand();
return command;
}
@Override final class CommandResult implements ResultedEvent.Result {
public CommandResult getResult() {
return result;
}
@Override
public void setResult(CommandResult result) {
this.result = Preconditions.checkNotNull(result, "result");
}
@Override
public String toString() {
return "CommandExecuteEvent{"
+ "commandSource=" + commandSource
+ ", command=" + command
+ ", result=" + result
+ '}';
}
/**
* Represents the result of the {@link CommandExecuteEvent}.
*/
public static final class CommandResult implements ResultedEvent.Result {
private static final CommandResult ALLOWED = new CommandResult(true, false, null); private static final CommandResult ALLOWED = new CommandResult(true, false, null);
private static final CommandResult DENIED = new CommandResult(false, false, null); private static final CommandResult DENIED = new CommandResult(false, false, null);
@ -105,6 +64,7 @@ public final class CommandExecuteEvent implements ResultedEvent<CommandResult> {
/** /**
* Allows the command to be sent, without modification. * Allows the command to be sent, without modification.
*
* @return the allowed result * @return the allowed result
*/ */
public static CommandResult allowed() { public static CommandResult allowed() {
@ -113,6 +73,7 @@ public final class CommandExecuteEvent implements ResultedEvent<CommandResult> {
/** /**
* Prevents the command from being executed. * Prevents the command from being executed.
*
* @return the denied result * @return the denied result
*/ */
public static CommandResult denied() { public static CommandResult denied() {
@ -121,6 +82,7 @@ public final class CommandExecuteEvent implements ResultedEvent<CommandResult> {
/** /**
* Prevents the command from being executed, but forward command to server. * Prevents the command from being executed, but forward command to server.
*
* @return the forward result * @return the forward result
*/ */
public static CommandResult forwardToServer() { public static CommandResult forwardToServer() {
@ -129,6 +91,7 @@ public final class CommandExecuteEvent implements ResultedEvent<CommandResult> {
/** /**
* Prevents the command from being executed on proxy, but forward command to server. * Prevents the command from being executed on proxy, but forward command to server.
*
* @param newCommand the command without first slash to use instead * @param newCommand the command without first slash to use instead
* @return a result with a new command being forwarded to server * @return a result with a new command being forwarded to server
*/ */
@ -139,6 +102,7 @@ public final class CommandExecuteEvent implements ResultedEvent<CommandResult> {
/** /**
* Allows the command to be executed, but silently replaced old command with another. * Allows the command to be executed, but silently replaced old command with another.
*
* @param newCommand the command to use instead without first slash * @param newCommand the command to use instead without first slash
* @return a result with a new command * @return a result with a new command
*/ */
@ -147,4 +111,5 @@ public final class CommandExecuteEvent implements ResultedEvent<CommandResult> {
return new CommandResult(true, false, newCommand); return new CommandResult(true, false, newCommand);
} }
} }
} }

Datei anzeigen

@ -0,0 +1,66 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.event.command;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.command.CommandSource;
/**
* This event is fired when someone executing command.
*/
public final class CommandExecuteEventImpl implements CommandExecuteEvent {
private final CommandSource commandSource;
private final String command;
private CommandResult result;
/**
* Constructs a CommandExecuteEvent.
* @param commandSource the source executing the command
* @param command the command being executed without first slash
*/
public CommandExecuteEventImpl(CommandSource commandSource, String command) {
this.commandSource = Preconditions.checkNotNull(commandSource, "commandSource");
this.command = Preconditions.checkNotNull(command, "command");
this.result = CommandResult.allowed();
}
@Override
public CommandSource getCommandSource() {
return commandSource;
}
/**
* Gets the original command being executed without first slash.
* @return the original command being executed
*/
@Override
public String getCommand() {
return command;
}
@Override
public CommandResult getResult() {
return result;
}
@Override
public void setResult(CommandResult result) {
this.result = Preconditions.checkNotNull(result, "result");
}
@Override
public String toString() {
return "CommandExecuteEvent{"
+ "commandSource=" + commandSource
+ ", command=" + command
+ ", result=" + result
+ '}';
}
}

Datei anzeigen

@ -7,9 +7,6 @@
package com.velocitypowered.api.event.command; package com.velocitypowered.api.event.command;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.Beta;
import com.mojang.brigadier.tree.RootCommandNode; import com.mojang.brigadier.tree.RootCommandNode;
import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.connection.Player;
@ -17,28 +14,9 @@ import com.velocitypowered.api.proxy.connection.Player;
* Allows plugins to modify the packet indicating commands available on the server to a * Allows plugins to modify the packet indicating commands available on the server to a
* Minecraft 1.13+ client. * Minecraft 1.13+ client.
*/ */
@Beta public interface PlayerAvailableCommandsEvent {
public class PlayerAvailableCommandsEvent {
private final Player player; Player getPlayer();
private final RootCommandNode<?> rootNode;
/** RootCommandNode<?> getRootNode();
* Constructs an available commands event.
* @param player the targeted player
* @param rootNode the Brigadier root node
*/
public PlayerAvailableCommandsEvent(Player player,
RootCommandNode<?> rootNode) {
this.player = checkNotNull(player, "player");
this.rootNode = checkNotNull(rootNode, "rootNode");
}
public Player getPlayer() {
return player;
}
public RootCommandNode<?> getRootNode() {
return rootNode;
}
} }

Datei anzeigen

@ -0,0 +1,46 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.event.command;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.annotations.Beta;
import com.mojang.brigadier.tree.RootCommandNode;
import com.velocitypowered.api.proxy.connection.Player;
/**
* Allows plugins to modify the packet indicating commands available on the server to a
* Minecraft 1.13+ client.
*/
@Beta
public class PlayerAvailableCommandsEventImpl implements PlayerAvailableCommandsEvent {
private final Player player;
private final RootCommandNode<?> rootNode;
/**
* Constructs an available commands event.
* @param player the targeted player
* @param rootNode the Brigadier root node
*/
public PlayerAvailableCommandsEventImpl(Player player,
RootCommandNode<?> rootNode) {
this.player = checkNotNull(player, "player");
this.rootNode = checkNotNull(rootNode, "rootNode");
}
@Override
public Player getPlayer() {
return player;
}
@Override
public RootCommandNode<?> getRootNode() {
return rootNode;
}
}

Datei anzeigen

@ -7,28 +7,9 @@
package com.velocitypowered.api.event.connection; package com.velocitypowered.api.event.connection;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.InboundConnection;
/** /**
* This event is fired when a handshake is established between a client and the proxy. * This event is fired when a handshake is established between a client and the proxy.
*/ */
public final class ConnectionHandshakeEvent { public interface ConnectionHandshakeEvent {
private final InboundConnection connection;
public ConnectionHandshakeEvent(InboundConnection connection) {
this.connection = Preconditions.checkNotNull(connection, "connection");
}
public InboundConnection getConnection() {
return connection;
}
@Override
public String toString() {
return "ConnectionHandshakeEvent{"
+ "connection=" + connection
+ '}';
}
} }

Datei anzeigen

@ -0,0 +1,34 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.event.connection;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.InboundConnection;
/**
* This event is fired when a handshake is established between a client and the proxy.
*/
public final class ConnectionHandshakeEventImpl implements ConnectionHandshakeEvent {
private final InboundConnection connection;
public ConnectionHandshakeEventImpl(InboundConnection connection) {
this.connection = Preconditions.checkNotNull(connection, "connection");
}
public InboundConnection getConnection() {
return connection;
}
@Override
public String toString() {
return "ConnectionHandshakeEvent{"
+ "connection=" + connection
+ '}';
}
}

Datei anzeigen

@ -7,40 +7,17 @@
package com.velocitypowered.api.event.connection; package com.velocitypowered.api.event.connection;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.InboundConnection; import com.velocitypowered.api.proxy.connection.InboundConnection;
import com.velocitypowered.api.proxy.server.ServerPing; import com.velocitypowered.api.proxy.server.ServerPing;
/** /**
* This event is fired when a server list ping request is sent by a remote client. * This event is fired when a server list ping request is sent by a remote client.
*/ */
public final class ProxyPingEvent { public interface ProxyPingEvent {
private final InboundConnection connection; InboundConnection getConnection();
private ServerPing ping;
public ProxyPingEvent(InboundConnection connection, ServerPing ping) { ServerPing getPing();
this.connection = Preconditions.checkNotNull(connection, "connection");
this.ping = Preconditions.checkNotNull(ping, "ping");
}
public InboundConnection getConnection() { void setPing(ServerPing ping);
return connection;
}
public ServerPing getPing() {
return ping;
}
public void setPing(ServerPing ping) {
this.ping = Preconditions.checkNotNull(ping, "ping");
}
@Override
public String toString() {
return "ProxyPingEvent{"
+ "connection=" + connection
+ ", ping=" + ping
+ '}';
}
} }

Datei anzeigen

@ -0,0 +1,49 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.event.connection;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.InboundConnection;
import com.velocitypowered.api.proxy.server.ServerPing;
/**
* This event is fired when a server list ping request is sent by a remote client.
*/
public final class ProxyPingEventImpl implements ProxyPingEvent {
private final InboundConnection connection;
private ServerPing ping;
public ProxyPingEventImpl(InboundConnection connection, ServerPing ping) {
this.connection = Preconditions.checkNotNull(connection, "connection");
this.ping = Preconditions.checkNotNull(ping, "ping");
}
@Override
public InboundConnection getConnection() {
return connection;
}
@Override
public ServerPing getPing() {
return ping;
}
@Override
public void setPing(ServerPing ping) {
this.ping = Preconditions.checkNotNull(ping, "ping");
}
@Override
public String toString() {
return "ProxyPingEvent{"
+ "connection=" + connection
+ ", ping=" + ping
+ '}';
}
}

Datei anzeigen

@ -7,81 +7,46 @@
package com.velocitypowered.api.event.connection; package com.velocitypowered.api.event.connection;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.server.QueryResponse; import com.velocitypowered.api.proxy.server.QueryResponse;
import java.net.InetAddress; import java.net.InetAddress;
/** /**
* This event is fired if proxy is getting queried over GS4 Query protocol. * This event is fired if proxy is getting queried over GS4 Query protocol.
*/ */
public final class ProxyQueryEvent { public interface ProxyQueryEvent {
private final QueryType queryType;
private final InetAddress querierAddress;
private QueryResponse response;
/**
* Creates a new event.
*
* @param queryType the type of query
* @param querierAddress the remote address for the query
* @param response the current query response
*/
public ProxyQueryEvent(QueryType queryType, InetAddress querierAddress, QueryResponse response) {
this.queryType = Preconditions.checkNotNull(queryType, "queryType");
this.querierAddress = Preconditions.checkNotNull(querierAddress, "querierAddress");
this.response = Preconditions.checkNotNull(response, "response");
}
/** /**
* Returns the kind of query the remote client is performing. * Returns the kind of query the remote client is performing.
* *
* @return query type * @return query type
*/ */
public QueryType getQueryType() { QueryType getQueryType();
return queryType;
}
/** /**
* Get the address of the client that sent this query. * Get the address of the client that sent this query.
* *
* @return querier address * @return querier address
*/ */
public InetAddress getQuerierAddress() { InetAddress getQuerierAddress();
return querierAddress;
}
/** /**
* Returns the current query response. * Returns the current query response.
* *
* @return the current query response * @return the current query response
*/ */
public QueryResponse getResponse() { QueryResponse getResponse();
return response;
}
/** /**
* Sets a new query response. * Sets a new query response.
* *
* @param response the new non-null query response * @param response the new non-null query response
*/ */
public void setResponse(QueryResponse response) { void setResponse(QueryResponse response);
this.response = Preconditions.checkNotNull(response, "response");
}
@Override
public String toString() {
return "ProxyQueryEvent{"
+ "queryType=" + queryType
+ ", querierAddress=" + querierAddress
+ ", response=" + response
+ '}';
}
/** /**
* Represents the type of query the client is asking for. * Represents the type of query the client is asking for.
*/ */
public enum QueryType { enum QueryType {
/** /**
* Basic query asks only a subset of information, such as hostname, game type (hardcoded to * Basic query asks only a subset of information, such as hostname, game type (hardcoded to
* <pre>MINECRAFT</pre>), map, current players, max players, proxy port and proxy hostname. * <pre>MINECRAFT</pre>), map, current players, max players, proxy port and proxy hostname.

Datei anzeigen

@ -0,0 +1,85 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.event.connection;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.server.QueryResponse;
import java.net.InetAddress;
/**
* This event is fired if proxy is getting queried over GS4 Query protocol.
*/
public final class ProxyQueryEventImpl implements ProxyQueryEvent {
private final QueryType queryType;
private final InetAddress querierAddress;
private QueryResponse response;
/**
* Creates a new event.
*
* @param queryType the type of query
* @param querierAddress the remote address for the query
* @param response the current query response
*/
public ProxyQueryEventImpl(QueryType queryType, InetAddress querierAddress, QueryResponse response) {
this.queryType = Preconditions.checkNotNull(queryType, "queryType");
this.querierAddress = Preconditions.checkNotNull(querierAddress, "querierAddress");
this.response = Preconditions.checkNotNull(response, "response");
}
/**
* Returns the kind of query the remote client is performing.
*
* @return query type
*/
@Override
public QueryType getQueryType() {
return queryType;
}
/**
* Get the address of the client that sent this query.
*
* @return querier address
*/
@Override
public InetAddress getQuerierAddress() {
return querierAddress;
}
/**
* Returns the current query response.
*
* @return the current query response
*/
@Override
public QueryResponse getResponse() {
return response;
}
/**
* Sets a new query response.
*
* @param response the new non-null query response
*/
@Override
public void setResponse(QueryResponse response) {
this.response = Preconditions.checkNotNull(response, "response");
}
@Override
public String toString() {
return "ProxyQueryEvent{"
+ "queryType=" + queryType
+ ", querierAddress=" + querierAddress
+ ", response=" + response
+ '}';
}
}

Datei anzeigen

@ -11,10 +11,6 @@ package com.velocitypowered.api.event.lifecycle;
* This event is fired by the proxy after plugins have been loaded but before the proxy starts * This event is fired by the proxy after plugins have been loaded but before the proxy starts
* accepting connections. * accepting connections.
*/ */
public final class ProxyInitializeEvent { public interface ProxyInitializeEvent {
@Override
public String toString() {
return "ProxyInitializeEvent";
}
} }

Datei anzeigen

@ -0,0 +1,20 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.event.lifecycle;
/**
* This event is fired by the proxy after plugins have been loaded but before the proxy starts
* accepting connections.
*/
public final class ProxyInitializeEventImpl implements ProxyInitializeEvent {
@Override
public String toString() {
return "ProxyInitializeEvent";
}
}

Datei anzeigen

@ -10,10 +10,6 @@ package com.velocitypowered.api.event.lifecycle;
/** /**
* This event is fired when the proxy is reloaded by the user using {@code /velocity reload}. * This event is fired when the proxy is reloaded by the user using {@code /velocity reload}.
*/ */
public class ProxyReloadEvent { public interface ProxyReloadEvent {
@Override
public String toString() {
return "ProxyReloadEvent";
}
} }

Datei anzeigen

@ -0,0 +1,19 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.event.lifecycle;
/**
* This event is fired when the proxy is reloaded by the user using {@code /velocity reload}.
*/
public class ProxyReloadEventImpl implements ProxyReloadEvent {
@Override
public String toString() {
return "ProxyReloadEvent";
}
}

Datei anzeigen

@ -11,10 +11,6 @@ package com.velocitypowered.api.event.lifecycle;
* This event is fired by the proxy after the proxy has stopped accepting connections but before the * This event is fired by the proxy after the proxy has stopped accepting connections but before the
* proxy process exits. * proxy process exits.
*/ */
public final class ProxyShutdownEvent { public interface ProxyShutdownEvent {
@Override
public String toString() {
return "ProxyShutdownEvent";
}
} }

Datei anzeigen

@ -0,0 +1,16 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.event.lifecycle;
public final class ProxyShutdownEventImpl implements ProxyShutdownEvent {
@Override
public String toString() {
return "ProxyShutdownEvent";
}
}

Datei anzeigen

@ -7,37 +7,15 @@
package com.velocitypowered.api.event.lifecycle.network; package com.velocitypowered.api.event.lifecycle.network;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.network.ListenerType; import com.velocitypowered.api.network.ListenerType;
import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
/** /**
* This event is fired by the proxy after a listener starts accepting connections. * This event is fired by the proxy after a listener starts accepting connections.
*/ */
public final class ListenerBoundEvent { public interface ListenerBoundEvent {
private final SocketAddress address; SocketAddress getAddress();
private final ListenerType listenerType;
public ListenerBoundEvent(SocketAddress address, ListenerType listenerType) { ListenerType getListenerType();
this.address = Preconditions.checkNotNull(address, "address");
this.listenerType = Preconditions.checkNotNull(listenerType, "listenerType");
}
public SocketAddress getAddress() {
return address;
}
public ListenerType getListenerType() {
return listenerType;
}
@Override
public String toString() {
return "ListenerBoundEvent{"
+ "address=" + address
+ ", listenerType=" + listenerType
+ '}';
}
} }

Datei anzeigen

@ -0,0 +1,44 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.event.lifecycle.network;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.network.ListenerType;
import java.net.SocketAddress;
/**
* This event is fired by the proxy after a listener starts accepting connections.
*/
public final class ListenerBoundEventImpl implements ListenerBoundEvent {
private final SocketAddress address;
private final ListenerType listenerType;
public ListenerBoundEventImpl(SocketAddress address, ListenerType listenerType) {
this.address = Preconditions.checkNotNull(address, "address");
this.listenerType = Preconditions.checkNotNull(listenerType, "listenerType");
}
@Override
public SocketAddress getAddress() {
return address;
}
@Override
public ListenerType getListenerType() {
return listenerType;
}
@Override
public String toString() {
return "ListenerBoundEvent{"
+ "address=" + address
+ ", listenerType=" + listenerType
+ '}';
}
}

Datei anzeigen

@ -7,37 +7,15 @@
package com.velocitypowered.api.event.lifecycle.network; package com.velocitypowered.api.event.lifecycle.network;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.network.ListenerType; import com.velocitypowered.api.network.ListenerType;
import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
/** /**
* This event is fired by the proxy before the proxy stops accepting connections. * This event is fired by the proxy before the proxy stops accepting connections.
*/ */
public final class ListenerClosedEvent { public interface ListenerClosedEvent {
private final SocketAddress address; SocketAddress getAddress();
private final ListenerType listenerType;
public ListenerClosedEvent(SocketAddress address, ListenerType listenerType) { ListenerType getListenerType();
this.address = Preconditions.checkNotNull(address, "address");
this.listenerType = Preconditions.checkNotNull(listenerType, "listenerType");
}
public SocketAddress getAddress() {
return address;
}
public ListenerType getListenerType() {
return listenerType;
}
@Override
public String toString() {
return "ListenerCloseEvent{"
+ "address=" + address
+ ", listenerType=" + listenerType
+ '}';
}
} }

Datei anzeigen

@ -0,0 +1,44 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.event.lifecycle.network;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.network.ListenerType;
import java.net.SocketAddress;
/**
* This event is fired by the proxy before the proxy stops accepting connections.
*/
public final class ListenerClosedEventImpl implements ListenerClosedEvent {
private final SocketAddress address;
private final ListenerType listenerType;
public ListenerClosedEventImpl(SocketAddress address, ListenerType listenerType) {
this.address = Preconditions.checkNotNull(address, "address");
this.listenerType = Preconditions.checkNotNull(listenerType, "listenerType");
}
@Override
public SocketAddress getAddress() {
return address;
}
@Override
public ListenerType getListenerType() {
return listenerType;
}
@Override
public String toString() {
return "ListenerCloseEvent{"
+ "address=" + address
+ ", listenerType=" + listenerType
+ '}';
}
}

Datei anzeigen

@ -7,7 +7,6 @@
package com.velocitypowered.api.event.permission; package com.velocitypowered.api.event.permission;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.permission.PermissionFunction; import com.velocitypowered.api.permission.PermissionFunction;
import com.velocitypowered.api.permission.PermissionProvider; import com.velocitypowered.api.permission.PermissionProvider;
import com.velocitypowered.api.permission.PermissionSubject; import com.velocitypowered.api.permission.PermissionSubject;
@ -18,20 +17,9 @@ import org.checkerframework.checker.nullness.qual.Nullable;
* *
* <p>This event is only called once per subject, on initialisation.</p> * <p>This event is only called once per subject, on initialisation.</p>
*/ */
public final class PermissionsSetupEvent { public interface PermissionsSetupEvent {
private final PermissionSubject subject; PermissionSubject getSubject();
private final PermissionProvider defaultProvider;
private PermissionProvider provider;
public PermissionsSetupEvent(PermissionSubject subject, PermissionProvider provider) {
this.subject = Preconditions.checkNotNull(subject, "subject");
this.provider = this.defaultProvider = Preconditions.checkNotNull(provider, "provider");
}
public PermissionSubject getSubject() {
return this.subject;
}
/** /**
* Uses the provider function to obtain a {@link PermissionFunction} for the subject. * Uses the provider function to obtain a {@link PermissionFunction} for the subject.
@ -39,13 +27,9 @@ public final class PermissionsSetupEvent {
* @param subject the subject * @param subject the subject
* @return the obtained permission function * @return the obtained permission function
*/ */
public PermissionFunction createFunction(PermissionSubject subject) { PermissionFunction createFunction(PermissionSubject subject);
return this.provider.createFunction(subject);
}
public PermissionProvider getProvider() { PermissionProvider getProvider();
return this.provider;
}
/** /**
* Sets the {@link PermissionFunction} that should be used for the subject. * Sets the {@link PermissionFunction} that should be used for the subject.
@ -55,16 +39,5 @@ public final class PermissionsSetupEvent {
* *
* @param provider the provider * @param provider the provider
*/ */
public void setProvider(@Nullable PermissionProvider provider) { void setProvider(@Nullable PermissionProvider provider);
this.provider = provider == null ? this.defaultProvider : provider;
}
@Override
public String toString() {
return "PermissionsSetupEvent{"
+ "subject=" + subject
+ ", defaultProvider=" + defaultProvider
+ ", provider=" + provider
+ '}';
}
} }

Datei anzeigen

@ -0,0 +1,74 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.event.permission;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.permission.PermissionFunction;
import com.velocitypowered.api.permission.PermissionProvider;
import com.velocitypowered.api.permission.PermissionSubject;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Called when a {@link PermissionSubject}'s permissions are being setup.
*
* <p>This event is only called once per subject, on initialisation.</p>
*/
public final class PermissionsSetupEventImpl implements PermissionsSetupEvent {
private final PermissionSubject subject;
private final PermissionProvider defaultProvider;
private PermissionProvider provider;
public PermissionsSetupEventImpl(PermissionSubject subject, PermissionProvider provider) {
this.subject = Preconditions.checkNotNull(subject, "subject");
this.provider = this.defaultProvider = Preconditions.checkNotNull(provider, "provider");
}
@Override
public PermissionSubject getSubject() {
return this.subject;
}
/**
* Uses the provider function to obtain a {@link PermissionFunction} for the subject.
*
* @param subject the subject
* @return the obtained permission function
*/
@Override
public PermissionFunction createFunction(PermissionSubject subject) {
return this.provider.createFunction(subject);
}
@Override
public PermissionProvider getProvider() {
return this.provider;
}
/**
* Sets the {@link PermissionFunction} that should be used for the subject.
*
* <p>Specifying <code>null</code> will reset the provider to the default
* instance given when the event was posted.</p>
*
* @param provider the provider
*/
@Override
public void setProvider(@Nullable PermissionProvider provider) {
this.provider = provider == null ? this.defaultProvider : provider;
}
@Override
public String toString() {
return "PermissionsSetupEvent{"
+ "subject=" + subject
+ ", defaultProvider=" + defaultProvider
+ ", provider=" + provider
+ '}';
}
}

Datei anzeigen

@ -7,38 +7,13 @@
package com.velocitypowered.api.event.player; package com.velocitypowered.api.event.player;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.connection.Player;
/** public interface DisconnectEvent {
* This event is fired when a player disconnects from the proxy. Operations on the provided player,
* aside from basic data retrieval operations, may behave in undefined ways.
*/
public final class DisconnectEvent {
private final Player player; Player getPlayer();
private final LoginStatus loginStatus;
public DisconnectEvent(Player player, LoginStatus loginStatus) { LoginStatus getLoginStatus();
this.player = Preconditions.checkNotNull(player, "player");
this.loginStatus = Preconditions.checkNotNull(loginStatus, "loginStatus");
}
public Player getPlayer() {
return player;
}
public LoginStatus getLoginStatus() {
return loginStatus;
}
@Override
public String toString() {
return "DisconnectEvent{"
+ "player=" + player + ", "
+ "loginStatus=" + loginStatus
+ '}';
}
public enum LoginStatus { public enum LoginStatus {

Datei anzeigen

@ -0,0 +1,45 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.event.player;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.Player;
/**
* This event is fired when a player disconnects from the proxy. Operations on the provided player,
* aside from basic data retrieval operations, may behave in undefined ways.
*/
public final class DisconnectEventImpl implements DisconnectEvent {
private final Player player;
private final LoginStatus loginStatus;
public DisconnectEventImpl(Player player, LoginStatus loginStatus) {
this.player = Preconditions.checkNotNull(player, "player");
this.loginStatus = Preconditions.checkNotNull(loginStatus, "loginStatus");
}
@Override
public Player getPlayer() {
return player;
}
@Override
public LoginStatus getLoginStatus() {
return loginStatus;
}
@Override
public String toString() {
return "DisconnectEvent{"
+ "player=" + player + ", "
+ "loginStatus=" + loginStatus
+ '}';
}
}

Datei anzeigen

@ -13,7 +13,7 @@ import com.velocitypowered.api.util.GameProfile;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* This event is fired after the {@link PreLoginEvent} in * This event is fired after the {@link PreLoginEventImpl} in
* order to set up the game profile for the user. This can be used to configure a custom profile for * 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. * a user, i.e. skin replacement.
*/ */

Datei anzeigen

@ -13,7 +13,6 @@ import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.RegisteredServer;
import java.util.Optional; import java.util.Optional;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
@ -22,79 +21,38 @@ import org.checkerframework.checker.nullness.qual.Nullable;
* Velocity will notify the user (if they are already connected to a server) or disconnect them * Velocity will notify the user (if they are already connected to a server) or disconnect them
* (if they are not on a server and no other servers are available). * (if they are not on a server and no other servers are available).
*/ */
public final class KickedFromServerEvent implements public interface KickedFromServerEvent extends
ResultedEvent<KickedFromServerEvent.ServerKickResult> { ResultedEvent<KickedFromServerEvent.ServerKickResult> {
private final Player player; Player getPlayer();
private final RegisteredServer server;
private final @Nullable Component originalReason;
private final boolean duringServerConnect;
private ServerKickResult result;
/** RegisteredServer getServer();
* Creates a {@code KickedFromServerEvent} instance.
* @param player the player affected
* @param server the server the player disconnected from
* @param originalReason the reason for being kicked, optional
* @param duringServerConnect whether or not the player was kicked during the connection process
* @param result the initial result
*/
public KickedFromServerEvent(Player player, RegisteredServer server,
net.kyori.adventure.text.@Nullable Component originalReason,
boolean duringServerConnect, ServerKickResult result) {
this.player = Preconditions.checkNotNull(player, "player");
this.server = Preconditions.checkNotNull(server, "server");
this.originalReason = originalReason;
this.duringServerConnect = duringServerConnect;
this.result = Preconditions.checkNotNull(result, "result");
}
@Override
public ServerKickResult getResult() {
return result;
}
@Override
public void setResult(@NonNull ServerKickResult result) {
this.result = Preconditions.checkNotNull(result, "result");
}
public Player getPlayer() {
return player;
}
public RegisteredServer getServer() {
return server;
}
/** /**
* Gets the reason the server kicked the player from the server. * Gets the reason the server kicked the player from the server.
*
* @return the server kicked the player from the server * @return the server kicked the player from the server
*/ */
public Optional<Component> getServerKickReason() { Optional<Component> getServerKickReason();
return Optional.ofNullable(originalReason);
}
/** /**
* Returns whether or not the player got kicked while connecting to another server. * Returns whether or not the player got kicked while connecting to another server.
* *
* @return whether or not the player got kicked * @return whether or not the player got kicked
*/ */
public boolean kickedDuringServerConnect() { boolean kickedDuringServerConnect();
return duringServerConnect;
}
/** /**
* Represents the base interface for {@link KickedFromServerEvent} results. * Represents the base interface for {@link KickedFromServerEvent} results.
*/ */
public interface ServerKickResult extends ResultedEvent.Result { public interface ServerKickResult extends Result {
} }
/** /**
* Tells the proxy to disconnect the player with the specified reason. * Tells the proxy to disconnect the player with the specified reason.
*/ */
public static final class DisconnectPlayer implements ServerKickResult { final class DisconnectPlayer implements ServerKickResult {
private final Component component; private final Component component;
@ -126,13 +84,13 @@ public final class KickedFromServerEvent implements
* Tells the proxy to redirect the player to another server. No messages will be sent from the * Tells the proxy to redirect the player to another server. No messages will be sent from the
* proxy when this result is used. * proxy when this result is used.
*/ */
public static final class RedirectPlayer implements ServerKickResult { final class RedirectPlayer implements ServerKickResult {
private final Component message; private final Component message;
private final RegisteredServer server; private final RegisteredServer server;
private RedirectPlayer(RegisteredServer server, private RedirectPlayer(RegisteredServer server,
net.kyori.adventure.text.@Nullable Component message) { @Nullable Component message) {
this.server = Preconditions.checkNotNull(server, "server"); this.server = Preconditions.checkNotNull(server, "server");
this.message = message; this.message = message;
} }
@ -171,7 +129,7 @@ public final class KickedFromServerEvent implements
* result to use if the player was trying to connect to a different server, otherwise it is * result to use if the player was trying to connect to a different server, otherwise it is
* treated like a {@link DisconnectPlayer} result. * treated like a {@link DisconnectPlayer} result.
*/ */
public static final class Notify implements ServerKickResult { final class Notify implements ServerKickResult {
private final Component message; private final Component message;

Datei anzeigen

@ -0,0 +1,89 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.event.player;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import java.util.Optional;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Fired when a player is kicked from a server. You may either allow Velocity to kick the player
* (with an optional reason override) or redirect the player to a separate server. By default,
* Velocity will notify the user (if they are already connected to a server) or disconnect them
* (if they are not on a server and no other servers are available).
*/
public final class KickedFromServerEventImpl implements KickedFromServerEvent {
private final Player player;
private final RegisteredServer server;
private final @Nullable Component originalReason;
private final boolean duringServerConnect;
private ServerKickResult result;
/**
* Creates a {@code KickedFromServerEvent} instance.
* @param player the player affected
* @param server the server the player disconnected from
* @param originalReason the reason for being kicked, optional
* @param duringServerConnect whether or not the player was kicked during the connection process
* @param result the initial result
*/
public KickedFromServerEventImpl(Player player, RegisteredServer server,
net.kyori.adventure.text.@Nullable Component originalReason,
boolean duringServerConnect, ServerKickResult result) {
this.player = Preconditions.checkNotNull(player, "player");
this.server = Preconditions.checkNotNull(server, "server");
this.originalReason = originalReason;
this.duringServerConnect = duringServerConnect;
this.result = Preconditions.checkNotNull(result, "result");
}
@Override
public ServerKickResult getResult() {
return result;
}
@Override
public void setResult(@NonNull ServerKickResult result) {
this.result = Preconditions.checkNotNull(result, "result");
}
@Override
public Player getPlayer() {
return player;
}
@Override
public RegisteredServer getServer() {
return server;
}
/**
* Gets the reason the server kicked the player from the server.
* @return the server kicked the player from the server
*/
@Override
public Optional<Component> getServerKickReason() {
return Optional.ofNullable(originalReason);
}
/**
* Returns whether or not the player got kicked while connecting to another server.
*
* @return whether or not the player got kicked
*/
@Override
public boolean kickedDuringServerConnect() {
return duringServerConnect;
}
}

Datei anzeigen

@ -7,7 +7,6 @@
package com.velocitypowered.api.event.player; package com.velocitypowered.api.event.player;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.event.ResultedEvent; import com.velocitypowered.api.event.ResultedEvent;
import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.connection.Player;
@ -15,35 +14,13 @@ import com.velocitypowered.api.proxy.connection.Player;
* This event is fired once the player has been authenticated but before they connect to a server on * This event is fired once the player has been authenticated but before they connect to a server on
* the proxy. * the proxy.
*/ */
public final class LoginEvent implements ResultedEvent<ResultedEvent.ComponentResult> { public interface LoginEvent extends ResultedEvent<ResultedEvent.ComponentResult> {
private final Player player; Player getPlayer();
private ComponentResult result;
public LoginEvent(Player player) {
this.player = Preconditions.checkNotNull(player, "player");
this.result = ComponentResult.allowed();
}
public Player getPlayer() {
return player;
}
@Override @Override
public ComponentResult getResult() { ComponentResult getResult();
return result;
}
@Override @Override
public void setResult(ComponentResult result) { void setResult(ComponentResult result);
this.result = Preconditions.checkNotNull(result, "result");
}
@Override
public String toString() {
return "LoginEvent{"
+ "player=" + player
+ ", result=" + result
+ '}';
}
} }

Datei anzeigen

@ -0,0 +1,49 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.event.player;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.Player;
/**
* This event is fired once the player has been authenticated but before they connect to a server on
* the proxy.
*/
public final class LoginEventImpl implements LoginEvent {
private final Player player;
private ComponentResult result;
public LoginEventImpl(Player player) {
this.player = Preconditions.checkNotNull(player, "player");
this.result = ComponentResult.allowed();
}
@Override
public Player getPlayer() {
return player;
}
@Override
public ComponentResult getResult() {
return result;
}
@Override
public void setResult(ComponentResult result) {
this.result = Preconditions.checkNotNull(result, "result");
}
@Override
public String toString() {
return "LoginEvent{"
+ "player=" + player
+ ", result=" + result
+ '}';
}
}

Datei anzeigen

@ -7,7 +7,6 @@
package com.velocitypowered.api.event.player; package com.velocitypowered.api.event.player;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
import java.util.List; import java.util.List;
@ -16,29 +15,9 @@ import java.util.List;
* This event is fired when a client ({@link Player}) sends a plugin message through the * This event is fired when a client ({@link Player}) sends a plugin message through the
* register channel. * register channel.
*/ */
public final class PlayerChannelRegisterEvent { public interface PlayerChannelRegisterEvent {
private final Player player; Player getPlayer();
private final List<ChannelIdentifier> channels;
public PlayerChannelRegisterEvent(Player player, List<ChannelIdentifier> channels) { List<ChannelIdentifier> getChannels();
this.player = Preconditions.checkNotNull(player, "player");
this.channels = Preconditions.checkNotNull(channels, "channels");
}
public Player getPlayer() {
return player;
}
public List<ChannelIdentifier> getChannels() {
return channels;
}
@Override
public String toString() {
return "PlayerChannelRegisterEvent{"
+ "player=" + player
+ ", channels=" + channels
+ '}';
}
} }

Datei anzeigen

@ -0,0 +1,46 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.event.player;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
import java.util.List;
/**
* This event is fired when a client ({@link Player}) sends a plugin message through the
* register channel.
*/
public final class PlayerChannelRegisterEventImpl implements PlayerChannelRegisterEvent {
private final Player player;
private final List<ChannelIdentifier> channels;
public PlayerChannelRegisterEventImpl(Player player, List<ChannelIdentifier> channels) {
this.player = Preconditions.checkNotNull(player, "player");
this.channels = Preconditions.checkNotNull(channels, "channels");
}
@Override
public Player getPlayer() {
return player;
}
@Override
public List<ChannelIdentifier> getChannels() {
return channels;
}
@Override
public String toString() {
return "PlayerChannelRegisterEvent{"
+ "player=" + player
+ ", channels=" + channels
+ '}';
}
}

Datei anzeigen

@ -14,57 +14,22 @@ import java.util.Optional;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
/** public interface PlayerChatEvent extends ResultedEvent<PlayerChatEvent.ChatResult> {
* This event is fired when a player types in a chat message.
*/
public final class PlayerChatEvent implements ResultedEvent<PlayerChatEvent.ChatResult> {
private final Player player; Player getPlayer();
private final String message;
private ChatResult result;
/** String getMessage();
* Constructs a PlayerChatEvent.
* @param player the player sending the message
* @param message the message being sent
*/
public PlayerChatEvent(Player player, String message) {
this.player = Preconditions.checkNotNull(player, "player");
this.message = Preconditions.checkNotNull(message, "message");
this.result = ChatResult.allowed();
}
public Player getPlayer() {
return player;
}
public String getMessage() {
return message;
}
@Override @Override
public ChatResult getResult() { ChatResult getResult();
return result;
}
@Override @Override
public void setResult(ChatResult result) { void setResult(ChatResult result);
this.result = Preconditions.checkNotNull(result, "result");
}
@Override
public String toString() {
return "PlayerChatEvent{"
+ "player=" + player
+ ", message=" + message
+ ", result=" + result
+ '}';
}
/** /**
* Represents the result of the {@link PlayerChatEvent}. * Represents the result of the {@link PlayerChatEvent}.
*/ */
public static final class ChatResult implements ResultedEvent.Result { final class ChatResult implements Result {
private static final ChatResult ALLOWED = new ChatResult(true, null); private static final ChatResult ALLOWED = new ChatResult(true, null);
private static final ChatResult DENIED = new ChatResult(false, null); private static final ChatResult DENIED = new ChatResult(false, null);
@ -93,6 +58,7 @@ public final class PlayerChatEvent implements ResultedEvent<PlayerChatEvent.Chat
/** /**
* Allows the message to be sent, without modification. * Allows the message to be sent, without modification.
*
* @return the allowed result * @return the allowed result
*/ */
public static ChatResult allowed() { public static ChatResult allowed() {
@ -101,6 +67,7 @@ public final class PlayerChatEvent implements ResultedEvent<PlayerChatEvent.Chat
/** /**
* Prevents the message from being sent. * Prevents the message from being sent.
*
* @return the denied result * @return the denied result
*/ */
public static ChatResult denied() { public static ChatResult denied() {
@ -109,6 +76,7 @@ public final class PlayerChatEvent implements ResultedEvent<PlayerChatEvent.Chat
/** /**
* Allows the message to be sent, but silently replaced with another. * Allows the message to be sent, but silently replaced with another.
*
* @param message the message to use instead * @param message the message to use instead
* @return a result with a new message * @return a result with a new message
*/ */

Datei anzeigen

@ -0,0 +1,62 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.event.player;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.Player;
/**
* This event is fired when a player types in a chat message.
*/
public final class PlayerChatEventImpl implements PlayerChatEvent {
private final Player player;
private final String message;
private ChatResult result;
/**
* Constructs a PlayerChatEvent.
* @param player the player sending the message
* @param message the message being sent
*/
public PlayerChatEventImpl(Player player, String message) {
this.player = Preconditions.checkNotNull(player, "player");
this.message = Preconditions.checkNotNull(message, "message");
this.result = ChatResult.allowed();
}
@Override
public Player getPlayer() {
return player;
}
@Override
public String getMessage() {
return message;
}
@Override
public ChatResult getResult() {
return result;
}
@Override
public void setResult(ChatResult result) {
this.result = Preconditions.checkNotNull(result, "result");
}
@Override
public String toString() {
return "PlayerChatEvent{"
+ "player=" + player
+ ", message=" + message
+ ", result=" + result
+ '}';
}
}

Datei anzeigen

@ -7,52 +7,24 @@
package com.velocitypowered.api.event.player; package com.velocitypowered.api.event.player;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.RegisteredServer;
import java.util.Optional; import java.util.Optional;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* Fired when a player has finished connecting to the proxy and we need to choose the first server * Fired when a player has finished connecting to the proxy and we need to choose the first server
* to connect to. * to connect to.
*/ */
public class PlayerChooseInitialServerEvent { public interface PlayerChooseInitialServerEvent {
private final Player player; Player getPlayer();
private @Nullable RegisteredServer initialServer;
/** Optional<RegisteredServer> getInitialServer();
* Constructs a PlayerChooseInitialServerEvent.
* @param player the player that was connected
* @param initialServer the initial server selected, may be {@code null}
*/
public PlayerChooseInitialServerEvent(Player player, @Nullable RegisteredServer initialServer) {
this.player = Preconditions.checkNotNull(player, "player");
this.initialServer = initialServer;
}
public Player getPlayer() {
return player;
}
public Optional<RegisteredServer> getInitialServer() {
return Optional.ofNullable(initialServer);
}
/** /**
* Sets the new initial server. * Sets the new initial server.
*
* @param server the initial server the player should connect to * @param server the initial server the player should connect to
*/ */
public void setInitialServer(RegisteredServer server) { void setInitialServer(RegisteredServer server);
this.initialServer = server;
}
@Override
public String toString() {
return "PlayerChooseInitialServerEvent{"
+ "player=" + player
+ ", initialServer=" + initialServer
+ '}';
}
} }

Datei anzeigen

@ -0,0 +1,61 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.event.player;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import java.util.Optional;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Fired when a player has finished connecting to the proxy and we need to choose the first server
* to connect to.
*/
public class PlayerChooseInitialServerEventImpl implements PlayerChooseInitialServerEvent {
private final Player player;
private @Nullable RegisteredServer initialServer;
/**
* Constructs a PlayerChooseInitialServerEvent.
* @param player the player that was connected
* @param initialServer the initial server selected, may be {@code null}
*/
public PlayerChooseInitialServerEventImpl(Player player, @Nullable RegisteredServer initialServer) {
this.player = Preconditions.checkNotNull(player, "player");
this.initialServer = initialServer;
}
@Override
public Player getPlayer() {
return player;
}
@Override
public Optional<RegisteredServer> getInitialServer() {
return Optional.ofNullable(initialServer);
}
/**
* Sets the new initial server.
* @param server the initial server the player should connect to
*/
@Override
public void setInitialServer(RegisteredServer server) {
this.initialServer = server;
}
@Override
public String toString() {
return "PlayerChooseInitialServerEvent{"
+ "player=" + player
+ ", initialServer=" + initialServer
+ '}';
}
}

Datei anzeigen

@ -7,37 +7,16 @@
package com.velocitypowered.api.event.player; package com.velocitypowered.api.event.player;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.util.ModInfo; import com.velocitypowered.api.util.ModInfo;
/** /**
* This event is fired when a Forge client sends its mods to the proxy while connecting to a server. * This event is fired when a modded client sends its mods to the proxy while connecting to a
* server.
*/ */
public final class PlayerModInfoEvent { public interface PlayerModInfoEvent {
private final Player player; Player getPlayer();
private final ModInfo modInfo;
public PlayerModInfoEvent(Player player, ModInfo modInfo) { ModInfo getModInfo();
this.player = Preconditions.checkNotNull(player, "player");
this.modInfo = Preconditions.checkNotNull(modInfo, "modInfo");
}
public Player getPlayer() {
return player;
}
public ModInfo getModInfo() {
return modInfo;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("player", player)
.add("modInfo", modInfo)
.toString();
}
} }

Datei anzeigen

@ -0,0 +1,42 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.event.player;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.util.ModInfo;
public final class PlayerModInfoEventImpl implements PlayerModInfoEvent {
private final Player player;
private final ModInfo modInfo;
public PlayerModInfoEventImpl(Player player, ModInfo modInfo) {
this.player = Preconditions.checkNotNull(player, "player");
this.modInfo = Preconditions.checkNotNull(modInfo, "modInfo");
}
@Override
public Player getPlayer() {
return player;
}
@Override
public ModInfo getModInfo() {
return modInfo;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("player", player)
.add("modInfo", modInfo)
.toString();
}
}

Datei anzeigen

@ -7,53 +7,32 @@
package com.velocitypowered.api.event.player; package com.velocitypowered.api.event.player;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.connection.Player;
/** /**
* This event is fired when the status of a resource pack sent to the player by the server is * This event is fired when the status of a resource pack sent to the player by the server is
* changed. * changed.
*/ */
public class PlayerResourcePackStatusEvent { public interface PlayerResourcePackStatusEvent {
private final Player player;
private final Status status;
public PlayerResourcePackStatusEvent(Player player, Status status) {
this.player = Preconditions.checkNotNull(player, "player");
this.status = Preconditions.checkNotNull(status, "status");
}
/** /**
* Returns the player affected by the change in resource pack status. * Returns the player affected by the change in resource pack status.
* *
* @return the player * @return the player
*/ */
public Player getPlayer() { Player getPlayer();
return player;
}
/** /**
* Returns the new status for the resource pack. * Returns the new status for the resource pack.
* *
* @return the new status * @return the new status
*/ */
public Status getStatus() { Status getStatus();
return status;
}
@Override
public String toString() {
return "PlayerResourcePackStatusEvent{"
+ "player=" + player
+ ", status=" + status
+ '}';
}
/** /**
* Represents the possible statuses for the resource pack. * Represents the possible statuses for the resource pack.
*/ */
public enum Status { enum Status {
/** /**
* The resource pack was applied successfully. * The resource pack was applied successfully.
*/ */

Datei anzeigen

@ -0,0 +1,55 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.event.player;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.Player;
/**
* This event is fired when the status of a resource pack sent to the player by the server is
* changed.
*/
public class PlayerResourcePackStatusEventImpl implements PlayerResourcePackStatusEvent {
private final Player player;
private final Status status;
public PlayerResourcePackStatusEventImpl(Player player, Status status) {
this.player = Preconditions.checkNotNull(player, "player");
this.status = Preconditions.checkNotNull(status, "status");
}
/**
* Returns the player affected by the change in resource pack status.
*
* @return the player
*/
@Override
public Player getPlayer() {
return player;
}
/**
* Returns the new status for the resource pack.
*
* @return the new status
*/
@Override
public Status getStatus() {
return status;
}
@Override
public String toString() {
return "PlayerResourcePackStatusEvent{"
+ "player=" + player
+ ", status=" + status
+ '}';
}
}

Datei anzeigen

@ -7,34 +7,12 @@
package com.velocitypowered.api.event.player; package com.velocitypowered.api.event.player;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.proxy.player.PlayerSettings; import com.velocitypowered.api.proxy.player.PlayerSettings;
public final class PlayerSettingsChangedEvent { public interface PlayerSettingsChangedEvent {
private final Player player; Player getPlayer();
private final PlayerSettings playerSettings;
public PlayerSettingsChangedEvent(Player player, PlayerSettings playerSettings) { PlayerSettings getPlayerSettings();
this.player = Preconditions.checkNotNull(player, "player");
this.playerSettings = Preconditions.checkNotNull(playerSettings, "playerSettings");
}
public Player getPlayer() {
return player;
}
public PlayerSettings getPlayerSettings() {
return playerSettings;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("player", player)
.add("playerSettings", playerSettings)
.toString();
}
} }

Datei anzeigen

@ -0,0 +1,42 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.event.player;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.proxy.player.PlayerSettings;
public final class PlayerSettingsChangedEventImpl implements PlayerSettingsChangedEvent {
private final Player player;
private final PlayerSettings playerSettings;
public PlayerSettingsChangedEventImpl(Player player, PlayerSettings playerSettings) {
this.player = Preconditions.checkNotNull(player, "player");
this.playerSettings = Preconditions.checkNotNull(playerSettings, "playerSettings");
}
@Override
public Player getPlayer() {
return player;
}
@Override
public PlayerSettings getPlayerSettings() {
return playerSettings;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("player", player)
.add("playerSettings", playerSettings)
.toString();
}
}

Datei anzeigen

@ -7,29 +7,13 @@
package com.velocitypowered.api.event.player; package com.velocitypowered.api.event.player;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.connection.Player;
/** /**
* This event is fired once the player has been fully initialized and is about to connect to their * This event is fired once the player has been fully initialized and is about to connect to their
* first server. * first server.
*/ */
public final class PostLoginEvent { public interface PostLoginEvent {
private final Player player; Player getPlayer();
public PostLoginEvent(Player player) {
this.player = Preconditions.checkNotNull(player, "player");
}
public Player getPlayer() {
return player;
}
@Override
public String toString() {
return "PostLoginEvent{"
+ "player=" + player
+ '}';
}
} }

Datei anzeigen

@ -0,0 +1,36 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.event.player;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.Player;
/**
* This event is fired once the player has been fully initialized and is about to connect to their
* first server.
*/
public final class PostLoginEventImpl implements PostLoginEvent {
private final Player player;
public PostLoginEventImpl(Player player) {
this.player = Preconditions.checkNotNull(player, "player");
}
@Override
public Player getPlayer() {
return player;
}
@Override
public String toString() {
return "PostLoginEvent{"
+ "player=" + player
+ '}';
}
}

Datei anzeigen

@ -20,55 +20,23 @@ import org.checkerframework.checker.nullness.qual.Nullable;
* authenticates the player with Mojang or before the player's proxy connection is fully established * authenticates the player with Mojang or before the player's proxy connection is fully established
* (for offline mode). * (for offline mode).
*/ */
public final class PreLoginEvent implements ResultedEvent<PreLoginEvent.PreLoginComponentResult> { public interface PreLoginEvent extends ResultedEvent<PreLoginEvent.PreLoginComponentResult> {
private final InboundConnection connection; InboundConnection getConnection();
private final String username;
private PreLoginComponentResult result;
/** String getUsername();
* Creates a new instance.
* @param connection the connection logging into the proxy
* @param username the player's username
*/
public PreLoginEvent(InboundConnection connection, String username) {
this.connection = Preconditions.checkNotNull(connection, "connection");
this.username = Preconditions.checkNotNull(username, "username");
this.result = PreLoginComponentResult.allowed();
}
public InboundConnection getConnection() {
return connection;
}
public String getUsername() {
return username;
}
@Override @Override
public PreLoginComponentResult getResult() { PreLoginComponentResult getResult();
return result;
}
@Override @Override
public void setResult(@NonNull PreLoginComponentResult result) { void setResult(@NonNull PreLoginComponentResult result);
this.result = Preconditions.checkNotNull(result, "result");
}
@Override
public String toString() {
return "PreLoginEvent{"
+ "connection=" + connection
+ ", username='" + username + '\''
+ ", result=" + result
+ '}';
}
/** /**
* Represents an "allowed/allowed with forced online\offline mode/denied" result with a reason * Represents an "allowed/allowed with forced online\offline mode/denied" result with a reason
* allowed for denial. * allowed for denial.
*/ */
public static final class PreLoginComponentResult implements ResultedEvent.Result { final class PreLoginComponentResult implements Result {
private static final PreLoginComponentResult ALLOWED = new PreLoginComponentResult( private static final PreLoginComponentResult ALLOWED = new PreLoginComponentResult(
Result.ALLOWED, null); Result.ALLOWED, null);

Datei anzeigen

@ -0,0 +1,65 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.event.player;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.InboundConnection;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* This event is fired when a player has initiated a connection with the proxy but before the proxy
* authenticates the player with Mojang or before the player's proxy connection is fully established
* (for offline mode).
*/
public final class PreLoginEventImpl implements PreLoginEvent {
private final InboundConnection connection;
private final String username;
private PreLoginComponentResult result;
/**
* Creates a new instance.
* @param connection the connection logging into the proxy
* @param username the player's username
*/
public PreLoginEventImpl(InboundConnection connection, String username) {
this.connection = Preconditions.checkNotNull(connection, "connection");
this.username = Preconditions.checkNotNull(username, "username");
this.result = PreLoginComponentResult.allowed();
}
@Override
public InboundConnection getConnection() {
return connection;
}
@Override
public String getUsername() {
return username;
}
@Override
public PreLoginComponentResult getResult() {
return result;
}
@Override
public void setResult(@NonNull PreLoginComponentResult result) {
this.result = Preconditions.checkNotNull(result, "result");
}
@Override
public String toString() {
return "PreLoginEvent{"
+ "connection=" + connection
+ ", username='" + username + '\''
+ ", result=" + result
+ '}';
}
}

Datei anzeigen

@ -7,53 +7,19 @@
package com.velocitypowered.api.event.player; package com.velocitypowered.api.event.player;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.RegisteredServer;
import java.util.Optional; import java.util.Optional;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* This event is fired once the player has successfully connected to the target server and the * This event is fired once the player has successfully connected to the target server and the
* connection to the previous server has been de-established. * connection to the previous server has been de-established.
*/ */
public final class ServerConnectedEvent { public interface ServerConnectedEvent {
private final Player player; Player getPlayer();
private final RegisteredServer server;
private final @Nullable RegisteredServer previousServer;
/** RegisteredServer getServer();
* Constructs a ServerConnectedEvent.
* @param player the player that was connected
* @param server the server the player was connected to
* @param previousServer the server the player was previously connected to, null if none
*/
public ServerConnectedEvent(Player player, RegisteredServer server,
@Nullable RegisteredServer previousServer) {
this.player = Preconditions.checkNotNull(player, "player");
this.server = Preconditions.checkNotNull(server, "server");
this.previousServer = previousServer;
}
public Player getPlayer() { Optional<RegisteredServer> getPreviousServer();
return player;
}
public RegisteredServer getServer() {
return server;
}
public Optional<RegisteredServer> getPreviousServer() {
return Optional.ofNullable(previousServer);
}
@Override
public String toString() {
return "ServerConnectedEvent{"
+ "player=" + player
+ ", server=" + server
+ ", previousServer=" + previousServer
+ '}';
}
} }

Datei anzeigen

@ -0,0 +1,62 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.event.player;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import java.util.Optional;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* This event is fired once the player has successfully connected to the target server and the
* connection to the previous server has been de-established.
*/
public final class ServerConnectedEventImpl implements ServerConnectedEvent {
private final Player player;
private final RegisteredServer server;
private final @Nullable RegisteredServer previousServer;
/**
* Constructs a ServerConnectedEvent.
* @param player the player that was connected
* @param server the server the player was connected to
* @param previousServer the server the player was previously connected to, null if none
*/
public ServerConnectedEventImpl(Player player, RegisteredServer server,
@Nullable RegisteredServer previousServer) {
this.player = Preconditions.checkNotNull(player, "player");
this.server = Preconditions.checkNotNull(server, "server");
this.previousServer = previousServer;
}
@Override
public Player getPlayer() {
return player;
}
@Override
public RegisteredServer getServer() {
return server;
}
@Override
public Optional<RegisteredServer> getPreviousServer() {
return Optional.ofNullable(previousServer);
}
@Override
public String toString() {
return "ServerConnectedEvent{"
+ "player=" + player
+ ", server=" + server
+ ", previousServer=" + previousServer
+ '}';
}
}

Datei anzeigen

@ -7,8 +7,6 @@
package com.velocitypowered.api.event.player; package com.velocitypowered.api.event.player;
import com.google.common.annotations.Beta;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.RegisteredServer;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -17,30 +15,9 @@ import org.checkerframework.checker.nullness.qual.Nullable;
* Fired after the player has connected to a server. The server the player is now connected to is * Fired after the player has connected to a server. The server the player is now connected to is
* available in {@link Player#getCurrentServer()}. * available in {@link Player#getCurrentServer()}.
*/ */
@Beta public interface ServerPostConnectEvent {
public class ServerPostConnectEvent {
private final Player player;
private final RegisteredServer previousServer;
public ServerPostConnectEvent(Player player, Player getPlayer();
@Nullable RegisteredServer previousServer) {
this.player = Preconditions.checkNotNull(player, "player");
this.previousServer = previousServer;
}
public Player getPlayer() { @Nullable RegisteredServer getPreviousServer();
return player;
}
public @Nullable RegisteredServer getPreviousServer() {
return previousServer;
}
@Override
public String toString() {
return "ServerPostConnectEvent{"
+ "player=" + player
+ ", previousServer=" + previousServer
+ '}';
}
} }

Datei anzeigen

@ -0,0 +1,47 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.event.player;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Fired after the player has connected to a server. The server the player is now connected to is
* available in {@link Player#getCurrentServer()}.
*/
public class ServerPostConnectEventImpl implements ServerPostConnectEvent {
private final Player player;
private final RegisteredServer previousServer;
public ServerPostConnectEventImpl(Player player,
@Nullable RegisteredServer previousServer) {
this.player = Preconditions.checkNotNull(player, "player");
this.previousServer = previousServer;
}
@Override
public Player getPlayer() {
return player;
}
@Override
public @Nullable RegisteredServer getPreviousServer() {
return previousServer;
}
@Override
public String toString() {
return "ServerPostConnectEvent{"
+ "player=" + player
+ ", previousServer=" + previousServer
+ '}';
}
}

Datei anzeigen

@ -19,65 +19,34 @@ import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* This event is fired before the player connects to a server. * This event is fired before the player connects to a server.
*/ */
public final class ServerPreConnectEvent implements public interface ServerPreConnectEvent extends ResultedEvent<ServerPreConnectEvent.ServerResult> {
ResultedEvent<ServerPreConnectEvent.ServerResult> {
private final Player player;
private final RegisteredServer originalServer;
private ServerResult result;
/**
* Creates the ServerPreConnectEvent.
* @param player the player who is connecting to a server
* @param originalServer the server the player was trying to connect to
*/
public ServerPreConnectEvent(Player player, RegisteredServer originalServer) {
this.player = Preconditions.checkNotNull(player, "player");
this.originalServer = Preconditions.checkNotNull(originalServer, "originalServer");
this.result = ServerResult.allowed(originalServer);
}
/** /**
* Returns the player connecting to the server. * Returns the player connecting to the server.
*
* @return the player connecting to the server * @return the player connecting to the server
*/ */
public Player getPlayer() { Player getPlayer();
return player;
}
@Override @Override
public ServerResult getResult() { ServerResult getResult();
return result;
}
@Override @Override
public void setResult(ServerResult result) { void setResult(ServerResult result);
this.result = Preconditions.checkNotNull(result, "result");
}
/** /**
* Returns the server that the player originally tried to connect to. To get the server the * Returns the server that the player originally tried to connect to. To get the server the player
* player will connect to, see the {@link ServerResult} of this event. To get the server the * will connect to, see the {@link ServerResult} of this event. To get the server the player is
* player is currently on when this event is fired, use {@link Player#getCurrentServer()}. * currently on when this event is fired, use {@link Player#getCurrentServer()}.
*
* @return the server that the player originally tried to connect to * @return the server that the player originally tried to connect to
*/ */
public RegisteredServer getOriginalServer() { RegisteredServer getOriginalServer();
return originalServer;
}
@Override
public String toString() {
return "ServerPreConnectEvent{"
+ "player=" + player
+ ", originalServer=" + originalServer
+ ", result=" + result
+ '}';
}
/** /**
* Represents the result of the {@link ServerPreConnectEvent}. * Represents the result of the {@link ServerPreConnectEvent}.
*/ */
public static class ServerResult implements ResultedEvent.Result { class ServerResult implements Result {
private static final ServerResult DENIED = new ServerResult(null); private static final ServerResult DENIED = new ServerResult(null);
@ -106,8 +75,9 @@ public final class ServerPreConnectEvent implements
/** /**
* Returns a result that will prevent players from connecting to another server. If this result * Returns a result that will prevent players from connecting to another server. If this result
* is used, then {@link ConnectionRequestBuilder#connect()}'s result will have the status * is used, then {@link ConnectionRequestBuilder#connect()}'s result will have the status {@link
* {@link Status#CONNECTION_CANCELLED}. * Status#CONNECTION_CANCELLED}.
*
* @return a result to deny conneections * @return a result to deny conneections
*/ */
public static ServerResult denied() { public static ServerResult denied() {
@ -116,6 +86,7 @@ public final class ServerPreConnectEvent implements
/** /**
* Allows the player to connect to the specified server. * Allows the player to connect to the specified server.
*
* @param server the new server to connect to * @param server the new server to connect to
* @return a result to allow the player to connect to the specified server * @return a result to allow the player to connect to the specified server
*/ */

Datei anzeigen

@ -0,0 +1,73 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.event.player;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.proxy.connection.Player;
import com.velocitypowered.api.proxy.server.RegisteredServer;
/**
* This event is fired before the player connects to a server.
*/
public final class ServerPreConnectEventImpl implements ServerPreConnectEvent {
private final Player player;
private final RegisteredServer originalServer;
private ServerResult result;
/**
* Creates the ServerPreConnectEvent.
* @param player the player who is connecting to a server
* @param originalServer the server the player was trying to connect to
*/
public ServerPreConnectEventImpl(Player player, RegisteredServer originalServer) {
this.player = Preconditions.checkNotNull(player, "player");
this.originalServer = Preconditions.checkNotNull(originalServer, "originalServer");
this.result = ServerResult.allowed(originalServer);
}
/**
* Returns the player connecting to the server.
* @return the player connecting to the server
*/
@Override
public Player getPlayer() {
return player;
}
@Override
public ServerResult getResult() {
return result;
}
@Override
public void setResult(ServerResult result) {
this.result = Preconditions.checkNotNull(result, "result");
}
/**
* Returns the server that the player originally tried to connect to. To get the server the
* player will connect to, see the {@link ServerResult} of this event. To get the server the
* player is currently on when this event is fired, use {@link Player#getCurrentServer()}.
* @return the server that the player originally tried to connect to
*/
@Override
public RegisteredServer getOriginalServer() {
return originalServer;
}
@Override
public String toString() {
return "ServerPreConnectEvent{"
+ "player=" + player
+ ", originalServer=" + originalServer
+ ", result=" + result
+ '}';
}
}

Datei anzeigen

@ -7,63 +7,33 @@
package com.velocitypowered.api.event.player; package com.velocitypowered.api.event.player;
import static com.google.common.base.Preconditions.checkNotNull;
import com.velocitypowered.api.proxy.connection.Player; import com.velocitypowered.api.proxy.connection.Player;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* This event is fired after a tab complete response is sent by the remote server, for clients on * This event is fired after a tab complete response is sent by the remote server, for clients on
* 1.12.2 and below. You have the opportunity to modify the response sent to the remote player. * 1.12.2 and below. You have the opportunity to modify the response sent to the remote player.
*/ */
public class TabCompleteEvent { public interface TabCompleteEvent {
private final Player player;
private final String partialMessage;
private final List<String> suggestions;
/**
* Constructs a new TabCompleteEvent instance.
* @param player the player
* @param partialMessage the partial message
* @param suggestions the initial list of suggestions
*/
public TabCompleteEvent(Player player, String partialMessage, List<String> suggestions) {
this.player = checkNotNull(player, "player");
this.partialMessage = checkNotNull(partialMessage, "partialMessage");
this.suggestions = new ArrayList<>(checkNotNull(suggestions, "suggestions"));
}
/** /**
* Returns the player requesting the tab completion. * Returns the player requesting the tab completion.
*
* @return the requesting player * @return the requesting player
*/ */
public Player getPlayer() { Player getPlayer();
return player;
}
/** /**
* Returns the message being partially completed. * Returns the message being partially completed.
*
* @return the partial message * @return the partial message
*/ */
public String getPartialMessage() { String getPartialMessage();
return partialMessage;
}
/** /**
* Returns all the suggestions provided to the user, as a mutable list. * Returns all the suggestions provided to the user, as a mutable list.
*
* @return the suggestions * @return the suggestions
*/ */
public List<String> getSuggestions() { List<String> getSuggestions();
return suggestions;
}
@Override
public String toString() {
return "TabCompleteEvent{"
+ "player=" + player
+ ", partialMessage='" + partialMessage + '\''
+ ", suggestions=" + suggestions
+ '}';
}
} }

Datei anzeigen

@ -0,0 +1,72 @@
/*
* Copyright (C) 2018 Velocity Contributors
*
* The Velocity API is licensed under the terms of the MIT License. For more details,
* reference the LICENSE file in the api top-level directory.
*/
package com.velocitypowered.api.event.player;
import static com.google.common.base.Preconditions.checkNotNull;
import com.velocitypowered.api.proxy.connection.Player;
import java.util.ArrayList;
import java.util.List;
/**
* This event is fired after a tab complete response is sent by the remote server, for clients on
* 1.12.2 and below. You have the opportunity to modify the response sent to the remote player.
*/
public class TabCompleteEventImpl implements TabCompleteEvent {
private final Player player;
private final String partialMessage;
private final List<String> suggestions;
/**
* Constructs a new TabCompleteEvent instance.
* @param player the player
* @param partialMessage the partial message
* @param suggestions the initial list of suggestions
*/
public TabCompleteEventImpl(Player player, String partialMessage, List<String> suggestions) {
this.player = checkNotNull(player, "player");
this.partialMessage = checkNotNull(partialMessage, "partialMessage");
this.suggestions = new ArrayList<>(checkNotNull(suggestions, "suggestions"));
}
/**
* Returns the player requesting the tab completion.
* @return the requesting player
*/
@Override
public Player getPlayer() {
return player;
}
/**
* Returns the message being partially completed.
* @return the partial message
*/
@Override
public String getPartialMessage() {
return partialMessage;
}
/**
* Returns all the suggestions provided to the user, as a mutable list.
* @return the suggestions
*/
@Override
public List<String> getSuggestions() {
return suggestions;
}
@Override
public String toString() {
return "TabCompleteEvent{"
+ "player=" + player
+ ", partialMessage='" + partialMessage + '\''
+ ", suggestions=" + suggestions
+ '}';
}
}

Datei anzeigen

@ -8,7 +8,7 @@
package com.velocitypowered.api.proxy.connection; package com.velocitypowered.api.proxy.connection;
import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.event.player.PlayerResourcePackStatusEvent; import com.velocitypowered.api.event.player.PlayerResourcePackStatusEventImpl;
import com.velocitypowered.api.proxy.messages.ChannelMessageSink; import com.velocitypowered.api.proxy.messages.ChannelMessageSink;
import com.velocitypowered.api.proxy.messages.ChannelMessageSource; import com.velocitypowered.api.proxy.messages.ChannelMessageSource;
import com.velocitypowered.api.proxy.player.ConnectionRequestBuilder; import com.velocitypowered.api.proxy.player.ConnectionRequestBuilder;
@ -123,7 +123,7 @@ public interface Player extends CommandSource, Identified, InboundConnection,
/** /**
* Sends the specified resource pack from {@code url} to the user. If at all possible, send the * Sends the specified resource pack from {@code url} to the user. If at all possible, send the
* resource pack using {@link #sendResourcePack(String, byte[])}. To monitor the status of the * resource pack using {@link #sendResourcePack(String, byte[])}. To monitor the status of the
* sent resource pack, subscribe to {@link PlayerResourcePackStatusEvent}. * sent resource pack, subscribe to {@link PlayerResourcePackStatusEventImpl}.
* *
* @param url the URL for the resource pack * @param url the URL for the resource pack
*/ */
@ -132,7 +132,7 @@ public interface Player extends CommandSource, Identified, InboundConnection,
/** /**
* Sends the specified resource pack from {@code url} to the user, using the specified 20-byte * Sends the specified resource pack from {@code url} to the user, using the specified 20-byte
* SHA-1 hash. To monitor the status of the sent resource pack, subscribe to * SHA-1 hash. To monitor the status of the sent resource pack, subscribe to
* {@link PlayerResourcePackStatusEvent}. * {@link PlayerResourcePackStatusEventImpl}.
* *
* @param url the URL for the resource pack * @param url the URL for the resource pack
* @param hash the SHA-1 hash value for the resource pack * @param hash the SHA-1 hash value for the resource pack

Datei anzeigen

@ -23,9 +23,9 @@ import com.google.common.collect.ImmutableList;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.velocitypowered.api.event.EventManager; import com.velocitypowered.api.event.EventManager;
import com.velocitypowered.api.event.lifecycle.ProxyInitializeEvent; import com.velocitypowered.api.event.lifecycle.ProxyInitializeEventImpl;
import com.velocitypowered.api.event.lifecycle.ProxyReloadEvent; import com.velocitypowered.api.event.lifecycle.ProxyReloadEventImpl;
import com.velocitypowered.api.event.lifecycle.ProxyShutdownEvent; import com.velocitypowered.api.event.lifecycle.ProxyShutdownEventImpl;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.plugin.PluginContainer; import com.velocitypowered.api.plugin.PluginContainer;
import com.velocitypowered.api.plugin.PluginManager; import com.velocitypowered.api.plugin.PluginManager;
@ -214,7 +214,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
// Go ahead and fire the proxy initialization event. We block since plugins should have a chance // Go ahead and fire the proxy initialization event. We block since plugins should have a chance
// to fully initialize before we accept any connections to the server. // to fully initialize before we accept any connections to the server.
eventManager.fire(new ProxyInitializeEvent()).join(); eventManager.fire(new ProxyInitializeEventImpl()).join();
// init console permissions after plugins are loaded // init console permissions after plugins are loaded
console.setupPermissions(); console.setupPermissions();
@ -390,7 +390,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
ipAttemptLimiter = Ratelimiters.createWithMilliseconds(newConfiguration.getLoginRatelimit()); ipAttemptLimiter = Ratelimiters.createWithMilliseconds(newConfiguration.getLoginRatelimit());
this.configuration = newConfiguration; this.configuration = newConfiguration;
eventManager.fireAndForget(new ProxyReloadEvent()); eventManager.fireAndForget(new ProxyReloadEventImpl());
return true; return true;
} }
@ -441,7 +441,7 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
} }
try { try {
eventManager.fire(new ProxyShutdownEvent()).get(10, TimeUnit.SECONDS); eventManager.fire(new ProxyShutdownEventImpl()).get(10, TimeUnit.SECONDS);
} catch (TimeoutException e) { } catch (TimeoutException e) {
timedOut = true; timedOut = true;
} catch (ExecutionException e) { } catch (ExecutionException e) {

Datei anzeigen

@ -34,6 +34,7 @@ import com.velocitypowered.api.command.RawCommand;
import com.velocitypowered.api.command.SimpleCommand; import com.velocitypowered.api.command.SimpleCommand;
import com.velocitypowered.api.event.command.CommandExecuteEvent; import com.velocitypowered.api.event.command.CommandExecuteEvent;
import com.velocitypowered.api.event.command.CommandExecuteEvent.CommandResult; import com.velocitypowered.api.event.command.CommandExecuteEvent.CommandResult;
import com.velocitypowered.api.event.command.CommandExecuteEventImpl;
import com.velocitypowered.proxy.event.VelocityEventManager; import com.velocitypowered.proxy.event.VelocityEventManager;
import com.velocitypowered.proxy.util.BrigadierUtils; import com.velocitypowered.proxy.util.BrigadierUtils;
import java.util.Iterator; import java.util.Iterator;
@ -117,7 +118,7 @@ public class VelocityCommandManager implements CommandManager {
} }
/** /**
* Fires a {@link CommandExecuteEvent}. * Fires a {@link CommandExecuteEventImpl}.
* *
* @param source the source to execute the command for * @param source the source to execute the command for
* @param cmdLine the command to execute * @param cmdLine the command to execute
@ -127,7 +128,7 @@ public class VelocityCommandManager implements CommandManager {
final String cmdLine) { final String cmdLine) {
Preconditions.checkNotNull(source, "source"); Preconditions.checkNotNull(source, "source");
Preconditions.checkNotNull(cmdLine, "cmdLine"); Preconditions.checkNotNull(cmdLine, "cmdLine");
return eventManager.fire(new CommandExecuteEvent(source, cmdLine)); return eventManager.fire(new CommandExecuteEventImpl(source, cmdLine));
} }
private boolean executeImmediately0(final CommandSource source, final String cmdLine) { private boolean executeImmediately0(final CommandSource source, final String cmdLine) {

Datei anzeigen

@ -24,7 +24,7 @@ import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.tree.CommandNode; import com.mojang.brigadier.tree.CommandNode;
import com.mojang.brigadier.tree.RootCommandNode; import com.mojang.brigadier.tree.RootCommandNode;
import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.event.command.PlayerAvailableCommandsEvent; import com.velocitypowered.api.event.command.PlayerAvailableCommandsEventImpl;
import com.velocitypowered.api.event.connection.PluginMessageEvent; import com.velocitypowered.api.event.connection.PluginMessageEvent;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
@ -214,7 +214,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
} }
server.getEventManager().fire( server.getEventManager().fire(
new PlayerAvailableCommandsEvent(serverConn.getPlayer(), rootNode)) new PlayerAvailableCommandsEventImpl(serverConn.getPlayer(), rootNode))
.thenAcceptAsync(event -> playerConnection.write(commands), playerConnection.eventLoop()) .thenAcceptAsync(event -> playerConnection.write(commands), playerConnection.eventLoop())
.exceptionally((ex) -> { .exceptionally((ex) -> {
logger.error("Exception while handling available commands for {}", playerConnection, ex); logger.error("Exception while handling available commands for {}", playerConnection, ex);

Datei anzeigen

@ -20,8 +20,8 @@ package com.velocitypowered.proxy.connection.backend;
import static com.velocitypowered.proxy.connection.backend.BackendConnectionPhases.IN_TRANSITION; import static com.velocitypowered.proxy.connection.backend.BackendConnectionPhases.IN_TRANSITION;
import static com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeHandshakeBackendPhase.HELLO; import static com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeHandshakeBackendPhase.HELLO;
import com.velocitypowered.api.event.player.ServerConnectedEvent; import com.velocitypowered.api.event.player.ServerConnectedEventImpl;
import com.velocitypowered.api.event.player.ServerPostConnectEvent; import com.velocitypowered.api.event.player.ServerPostConnectEventImpl;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.connection.ConnectionTypes; import com.velocitypowered.proxy.connection.ConnectionTypes;
import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnection;
@ -101,7 +101,7 @@ public class TransitionSessionHandler implements MinecraftSessionHandler {
// The goods are in hand! We got JoinGame. Let's transition completely to the new state. // The goods are in hand! We got JoinGame. Let's transition completely to the new state.
smc.setAutoReading(false); smc.setAutoReading(false);
server.getEventManager() server.getEventManager()
.fire(new ServerConnectedEvent(player, serverConn.getServer(), .fire(new ServerConnectedEventImpl(player, serverConn.getServer(),
existingConnection != null ? existingConnection.getServer() : null)) existingConnection != null ? existingConnection.getServer() : null))
.thenRunAsync(() -> { .thenRunAsync(() -> {
// Make sure we can still transition (player might have disconnected here). // Make sure we can still transition (player might have disconnected here).
@ -132,7 +132,7 @@ public class TransitionSessionHandler implements MinecraftSessionHandler {
serverConn.getPlayer().setConnectedServer(serverConn); serverConn.getPlayer().setConnectedServer(serverConn);
// We're done! :) // We're done! :)
server.getEventManager().fireAndForget(new ServerPostConnectEvent(player, server.getEventManager().fireAndForget(new ServerPostConnectEventImpl(player,
existingConnection == null ? null : existingConnection.getServer())); existingConnection == null ? null : existingConnection.getServer()));
resultFuture.complete(ConnectionRequestResults.successful(serverConn.getServer())); resultFuture.complete(ConnectionRequestResults.successful(serverConn.getServer()));
}, smc.eventLoop()) }, smc.eventLoop())

Datei anzeigen

@ -25,10 +25,11 @@ import static com.velocitypowered.proxy.network.PluginMessageUtil.constructChann
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.event.command.CommandExecuteEvent.CommandResult; import com.velocitypowered.api.event.command.CommandExecuteEvent.CommandResult;
import com.velocitypowered.api.event.connection.PluginMessageEvent; import com.velocitypowered.api.event.connection.PluginMessageEvent;
import com.velocitypowered.api.event.player.PlayerChannelRegisterEvent; import com.velocitypowered.api.event.player.PlayerChannelRegisterEventImpl;
import com.velocitypowered.api.event.player.PlayerChatEvent; import com.velocitypowered.api.event.player.PlayerChatEvent;
import com.velocitypowered.api.event.player.PlayerResourcePackStatusEvent; import com.velocitypowered.api.event.player.PlayerChatEventImpl;
import com.velocitypowered.api.event.player.TabCompleteEvent; import com.velocitypowered.api.event.player.PlayerResourcePackStatusEventImpl;
import com.velocitypowered.api.event.player.TabCompleteEventImpl;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.messages.ChannelIdentifier; import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier; import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier;
@ -173,10 +174,10 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
return null; return null;
}); });
} else { } else {
PlayerChatEvent event = new PlayerChatEvent(player, msg); PlayerChatEvent event = new PlayerChatEventImpl(player, msg);
server.getEventManager().fire(event) server.getEventManager().fire(event)
.thenAcceptAsync(pme -> { .thenAcceptAsync(pme -> {
PlayerChatEvent.ChatResult chatResult = pme.getResult(); PlayerChatEventImpl.ChatResult chatResult = pme.getResult();
if (chatResult.isAllowed()) { if (chatResult.isAllowed()) {
Optional<String> eventMsg = pme.getResult().getMessage(); Optional<String> eventMsg = pme.getResult().getMessage();
if (eventMsg.isPresent()) { if (eventMsg.isPresent()) {
@ -224,7 +225,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
channelIdentifiers.add(new LegacyChannelIdentifier(channel)); channelIdentifiers.add(new LegacyChannelIdentifier(channel));
} }
} }
server.getEventManager().fireAndForget(new PlayerChannelRegisterEvent(player, server.getEventManager().fireAndForget(new PlayerChannelRegisterEventImpl(player,
ImmutableList.copyOf(channelIdentifiers))); ImmutableList.copyOf(channelIdentifiers)));
backendConn.write(packet.retain()); backendConn.write(packet.retain());
} else if (PluginMessageUtil.isUnregister(packet)) { } else if (PluginMessageUtil.isUnregister(packet)) {
@ -286,7 +287,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
@Override @Override
public boolean handle(ServerboundResourcePackResponsePacket packet) { public boolean handle(ServerboundResourcePackResponsePacket packet) {
server.getEventManager().fireAndForget(new PlayerResourcePackStatusEvent(player, server.getEventManager().fireAndForget(new PlayerResourcePackStatusEventImpl(player,
packet.getStatus())); packet.getStatus()));
return false; return false;
} }
@ -576,7 +577,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
for (Offer offer : response.getOffers()) { for (Offer offer : response.getOffers()) {
offers.add(offer.getText()); offers.add(offer.getText());
} }
server.getEventManager().fire(new TabCompleteEvent(player, request.getCommand(), offers)) server.getEventManager().fire(new TabCompleteEventImpl(player, request.getCommand(), offers))
.thenAcceptAsync(e -> { .thenAcceptAsync(e -> {
response.getOffers().clear(); response.getOffers().clear();
for (String s : e.getSuggestions()) { for (String s : e.getSuggestions()) {

Datei anzeigen

@ -25,14 +25,17 @@ import com.google.common.base.Preconditions;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.velocitypowered.api.event.player.DisconnectEvent; import com.velocitypowered.api.event.player.DisconnectEvent;
import com.velocitypowered.api.event.player.DisconnectEvent.LoginStatus; import com.velocitypowered.api.event.player.DisconnectEvent.LoginStatus;
import com.velocitypowered.api.event.player.DisconnectEventImpl;
import com.velocitypowered.api.event.player.KickedFromServerEvent; import com.velocitypowered.api.event.player.KickedFromServerEvent;
import com.velocitypowered.api.event.player.KickedFromServerEvent.DisconnectPlayer; import com.velocitypowered.api.event.player.KickedFromServerEvent.DisconnectPlayer;
import com.velocitypowered.api.event.player.KickedFromServerEvent.Notify; import com.velocitypowered.api.event.player.KickedFromServerEvent.Notify;
import com.velocitypowered.api.event.player.KickedFromServerEvent.RedirectPlayer; import com.velocitypowered.api.event.player.KickedFromServerEvent.RedirectPlayer;
import com.velocitypowered.api.event.player.KickedFromServerEvent.ServerKickResult; import com.velocitypowered.api.event.player.KickedFromServerEvent.ServerKickResult;
import com.velocitypowered.api.event.player.PlayerModInfoEvent; import com.velocitypowered.api.event.player.KickedFromServerEventImpl;
import com.velocitypowered.api.event.player.PlayerSettingsChangedEvent; import com.velocitypowered.api.event.player.PlayerModInfoEventImpl;
import com.velocitypowered.api.event.player.PlayerSettingsChangedEventImpl;
import com.velocitypowered.api.event.player.ServerPreConnectEvent; import com.velocitypowered.api.event.player.ServerPreConnectEvent;
import com.velocitypowered.api.event.player.ServerPreConnectEventImpl;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.permission.PermissionFunction; import com.velocitypowered.api.permission.PermissionFunction;
import com.velocitypowered.api.permission.PermissionProvider; import com.velocitypowered.api.permission.PermissionProvider;
@ -59,7 +62,6 @@ import com.velocitypowered.proxy.network.StateRegistry;
import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket; import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundChatPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundChatPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundHeaderAndFooterPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundKeepAlivePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundKeepAlivePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPluginMessagePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundResourcePackRequestPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundResourcePackRequestPacket;
@ -212,7 +214,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
void setPlayerSettings(ServerboundClientSettingsPacket settings) { void setPlayerSettings(ServerboundClientSettingsPacket settings) {
ClientSettingsWrapper cs = new ClientSettingsWrapper(settings); ClientSettingsWrapper cs = new ClientSettingsWrapper(settings);
this.settings = cs; this.settings = cs;
server.getEventManager().fireAndForget(new PlayerSettingsChangedEvent(this, cs)); server.getEventManager().fireAndForget(new PlayerSettingsChangedEventImpl(this, cs));
} }
@Override @Override
@ -222,7 +224,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
public void setModInfo(ModInfo modInfo) { public void setModInfo(ModInfo modInfo) {
this.modInfo = modInfo; this.modInfo = modInfo;
server.getEventManager().fireAndForget(new PlayerModInfoEvent(this, modInfo)); server.getEventManager().fireAndForget(new PlayerModInfoEventImpl(this, modInfo));
} }
@Override @Override
@ -505,7 +507,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
} }
result = Notify.create(friendlyReason); result = Notify.create(friendlyReason);
} }
KickedFromServerEvent originalEvent = new KickedFromServerEvent(this, rs, kickReason, KickedFromServerEvent originalEvent = new KickedFromServerEventImpl(this, rs, kickReason,
!kickedFromCurrent, result); !kickedFromCurrent, result);
handleKickEvent(originalEvent, friendlyReason, kickedFromCurrent); handleKickEvent(originalEvent, friendlyReason, kickedFromCurrent);
} }
@ -669,7 +671,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
Optional<Player> connectedPlayer = server.getPlayer(this.getUniqueId()); Optional<Player> connectedPlayer = server.getPlayer(this.getUniqueId());
server.unregisterConnection(this); server.unregisterConnection(this);
DisconnectEvent.LoginStatus status; DisconnectEventImpl.LoginStatus status;
if (connectedPlayer.isPresent()) { if (connectedPlayer.isPresent()) {
if (!connectedPlayer.get().getCurrentServer().isPresent()) { if (!connectedPlayer.get().getCurrentServer().isPresent()) {
status = LoginStatus.PRE_SERVER_JOIN; status = LoginStatus.PRE_SERVER_JOIN;
@ -682,7 +684,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
LoginStatus.CANCELLED_BY_USER; LoginStatus.CANCELLED_BY_USER;
} }
DisconnectEvent event = new DisconnectEvent(this, status); DisconnectEvent event = new DisconnectEventImpl(this, status);
server.getEventManager().fire(event).whenComplete((val, ex) -> { server.getEventManager().fire(event).whenComplete((val, ex) -> {
if (ex == null) { if (ex == null) {
this.teardownFuture.complete(null); this.teardownFuture.complete(null);
@ -852,7 +854,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
return completedFuture(plainResult(initialCheck.get(), toConnect)); return completedFuture(plainResult(initialCheck.get(), toConnect));
} }
ServerPreConnectEvent event = new ServerPreConnectEvent(ConnectedPlayer.this, ServerPreConnectEvent event = new ServerPreConnectEventImpl(ConnectedPlayer.this,
toConnect); toConnect);
return server.getEventManager().fire(event) return server.getEventManager().fire(event)
.thenComposeAsync(newEvent -> { .thenComposeAsync(newEvent -> {

Datei anzeigen

@ -19,7 +19,7 @@ package com.velocitypowered.proxy.connection.client;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.event.connection.ConnectionHandshakeEvent; import com.velocitypowered.api.event.connection.ConnectionHandshakeEventImpl;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.connection.InboundConnection; import com.velocitypowered.api.proxy.connection.InboundConnection;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
@ -136,7 +136,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
return; return;
} }
server.getEventManager().fireAndForget(new ConnectionHandshakeEvent(ic)); server.getEventManager().fireAndForget(new ConnectionHandshakeEventImpl(ic));
connection.setSessionHandler(new LoginSessionHandler(server, connection, ic)); connection.setSessionHandler(new LoginSessionHandler(server, connection, ic));
} }

Datei anzeigen

@ -25,15 +25,17 @@ import static com.velocitypowered.proxy.util.EncryptionUtils.decryptRsa;
import static com.velocitypowered.proxy.util.EncryptionUtils.generateServerId; import static com.velocitypowered.proxy.util.EncryptionUtils.generateServerId;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.event.permission.PermissionsSetupEvent; import com.velocitypowered.api.event.permission.PermissionsSetupEventImpl;
import com.velocitypowered.api.event.player.DisconnectEvent;
import com.velocitypowered.api.event.player.DisconnectEvent.LoginStatus; import com.velocitypowered.api.event.player.DisconnectEvent.LoginStatus;
import com.velocitypowered.api.event.player.DisconnectEventImpl;
import com.velocitypowered.api.event.player.GameProfileRequestEvent; import com.velocitypowered.api.event.player.GameProfileRequestEvent;
import com.velocitypowered.api.event.player.LoginEvent; import com.velocitypowered.api.event.player.LoginEventImpl;
import com.velocitypowered.api.event.player.PlayerChooseInitialServerEvent; import com.velocitypowered.api.event.player.PlayerChooseInitialServerEvent;
import com.velocitypowered.api.event.player.PostLoginEvent; import com.velocitypowered.api.event.player.PlayerChooseInitialServerEventImpl;
import com.velocitypowered.api.event.player.PostLoginEventImpl;
import com.velocitypowered.api.event.player.PreLoginEvent; import com.velocitypowered.api.event.player.PreLoginEvent;
import com.velocitypowered.api.event.player.PreLoginEvent.PreLoginComponentResult; import com.velocitypowered.api.event.player.PreLoginEvent.PreLoginComponentResult;
import com.velocitypowered.api.event.player.PreLoginEventImpl;
import com.velocitypowered.api.permission.PermissionFunction; import com.velocitypowered.api.permission.PermissionFunction;
import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.RegisteredServer;
import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.api.util.GameProfile;
@ -176,7 +178,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
if (login == null) { if (login == null) {
throw new IllegalStateException("No ServerLogin packet received yet."); throw new IllegalStateException("No ServerLogin packet received yet.");
} }
PreLoginEvent event = new PreLoginEvent(inbound, login.getUsername()); PreLoginEvent event = new PreLoginEventImpl(inbound, login.getUsername());
server.getEventManager().fire(event) server.getEventManager().fire(event)
.thenRunAsync(() -> { .thenRunAsync(() -> {
if (mcConnection.isClosed()) { if (mcConnection.isClosed()) {
@ -245,7 +247,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
logger.info("{} has connected", player); logger.info("{} has connected", player);
return server.getEventManager() return server.getEventManager()
.fire(new PermissionsSetupEvent(player, ConnectedPlayer.DEFAULT_PERMISSIONS)) .fire(new PermissionsSetupEventImpl(player, ConnectedPlayer.DEFAULT_PERMISSIONS))
.thenAcceptAsync(event -> { .thenAcceptAsync(event -> {
if (!mcConnection.isClosed()) { if (!mcConnection.isClosed()) {
// wait for permissions to load, then set the players permission function // wait for permissions to load, then set the players permission function
@ -285,11 +287,11 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
mcConnection.setAssociation(player); mcConnection.setAssociation(player);
mcConnection.setState(StateRegistry.PLAY); mcConnection.setState(StateRegistry.PLAY);
server.getEventManager().fire(new LoginEvent(player)) server.getEventManager().fire(new LoginEventImpl(player))
.thenAcceptAsync(event -> { .thenAcceptAsync(event -> {
if (mcConnection.isClosed()) { if (mcConnection.isClosed()) {
// The player was disconnected // The player was disconnected
server.getEventManager().fireAndForget(new DisconnectEvent(player, server.getEventManager().fireAndForget(new DisconnectEventImpl(player,
LoginStatus.CANCELLED_BY_USER_BEFORE_COMPLETE)); LoginStatus.CANCELLED_BY_USER_BEFORE_COMPLETE));
return; return;
} }
@ -305,7 +307,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
} }
mcConnection.setSessionHandler(new InitialConnectSessionHandler(player)); mcConnection.setSessionHandler(new InitialConnectSessionHandler(player));
server.getEventManager().fire(new PostLoginEvent(player)) server.getEventManager().fire(new PostLoginEventImpl(player))
.thenCompose((ignored) -> connectToInitialServer(player)) .thenCompose((ignored) -> connectToInitialServer(player))
.exceptionally((ex) -> { .exceptionally((ex) -> {
logger.error("Exception while connecting {} to initial server", player, ex); logger.error("Exception while connecting {} to initial server", player, ex);
@ -321,7 +323,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
private CompletableFuture<Void> connectToInitialServer(ConnectedPlayer player) { private CompletableFuture<Void> connectToInitialServer(ConnectedPlayer player) {
Optional<RegisteredServer> initialFromConfig = player.getNextServerToTry(); Optional<RegisteredServer> initialFromConfig = player.getNextServerToTry();
PlayerChooseInitialServerEvent event = new PlayerChooseInitialServerEvent(player, PlayerChooseInitialServerEvent event = new PlayerChooseInitialServerEventImpl(player,
initialFromConfig.orElse(null)); initialFromConfig.orElse(null));
return server.getEventManager().fire(event) return server.getEventManager().fire(event)

Datei anzeigen

@ -19,7 +19,7 @@ package com.velocitypowered.proxy.connection.client;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.spotify.futures.CompletableFutures; import com.spotify.futures.CompletableFutures;
import com.velocitypowered.api.event.connection.ProxyPingEvent; import com.velocitypowered.api.event.connection.ProxyPingEventImpl;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.connection.InboundConnection; import com.velocitypowered.api.proxy.connection.InboundConnection;
import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.RegisteredServer;
@ -182,7 +182,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
} }
this.pingReceived = true; this.pingReceived = true;
getInitialPing() getInitialPing()
.thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inbound, ping))) .thenCompose(ping -> server.getEventManager().fire(new ProxyPingEventImpl(inbound, ping)))
.thenAcceptAsync(event -> connection.closeWith( .thenAcceptAsync(event -> connection.closeWith(
LegacyDisconnectPacket.fromServerPing(event.getPing(), packet.getVersion())), LegacyDisconnectPacket.fromServerPing(event.getPing(), packet.getVersion())),
connection.eventLoop()) connection.eventLoop())
@ -207,7 +207,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
this.pingReceived = true; this.pingReceived = true;
getInitialPing() getInitialPing()
.thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inbound, ping))) .thenCompose(ping -> server.getEventManager().fire(new ProxyPingEventImpl(inbound, ping)))
.thenAcceptAsync( .thenAcceptAsync(
(event) -> { (event) -> {
StringBuilder json = new StringBuilder(); StringBuilder json = new StringBuilder();

Datei anzeigen

@ -21,6 +21,7 @@ import static com.velocitypowered.api.permission.PermissionFunction.ALWAYS_TRUE;
import com.velocitypowered.api.command.ConsoleCommandSource; import com.velocitypowered.api.command.ConsoleCommandSource;
import com.velocitypowered.api.event.permission.PermissionsSetupEvent; import com.velocitypowered.api.event.permission.PermissionsSetupEvent;
import com.velocitypowered.api.event.permission.PermissionsSetupEventImpl;
import com.velocitypowered.api.permission.PermissionFunction; import com.velocitypowered.api.permission.PermissionFunction;
import com.velocitypowered.api.permission.Tristate; import com.velocitypowered.api.permission.Tristate;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
@ -72,7 +73,7 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons
* Sets up permissions for the console. * Sets up permissions for the console.
*/ */
public void setupPermissions() { public void setupPermissions() {
PermissionsSetupEvent event = new PermissionsSetupEvent(this, s -> ALWAYS_TRUE); PermissionsSetupEvent event = new PermissionsSetupEventImpl(this, s -> ALWAYS_TRUE);
// we can safely block here, this is before any listeners fire // we can safely block here, this is before any listeners fire
this.permissionFunction = this.server.getEventManager().fire(event).join().createFunction(this); this.permissionFunction = this.server.getEventManager().fire(event).join().createFunction(this);
if (this.permissionFunction == null) { if (this.permissionFunction == null) {

Datei anzeigen

@ -21,8 +21,8 @@ import static org.asynchttpclient.Dsl.asyncHttpClient;
import static org.asynchttpclient.Dsl.config; import static org.asynchttpclient.Dsl.config;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.event.lifecycle.network.ListenerBoundEvent; import com.velocitypowered.api.event.lifecycle.network.ListenerBoundEventImpl;
import com.velocitypowered.api.event.lifecycle.network.ListenerClosedEvent; import com.velocitypowered.api.event.lifecycle.network.ListenerClosedEventImpl;
import com.velocitypowered.api.network.ListenerType; import com.velocitypowered.api.network.ListenerType;
import com.velocitypowered.natives.util.Natives; import com.velocitypowered.natives.util.Natives;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
@ -136,7 +136,7 @@ public final class ConnectionManager {
// Fire the proxy bound event after the socket is bound // Fire the proxy bound event after the socket is bound
server.getEventManager().fireAndForget( server.getEventManager().fireAndForget(
new ListenerBoundEvent(address, ListenerType.MINECRAFT)); new ListenerBoundEventImpl(address, ListenerType.MINECRAFT));
} else { } else {
LOGGER.error("Can't bind to {}", address, future.cause()); LOGGER.error("Can't bind to {}", address, future.cause());
} }
@ -165,7 +165,7 @@ public final class ConnectionManager {
// Fire the proxy bound event after the socket is bound // Fire the proxy bound event after the socket is bound
server.getEventManager().fireAndForget( server.getEventManager().fireAndForget(
new ListenerBoundEvent(address, ListenerType.QUERY)); new ListenerBoundEventImpl(address, ListenerType.QUERY));
} else { } else {
LOGGER.error("Can't bind to {}", bootstrap.config().localAddress(), future.cause()); LOGGER.error("Can't bind to {}", bootstrap.config().localAddress(), future.cause());
} }
@ -203,7 +203,7 @@ public final class ConnectionManager {
// Fire proxy close event to notify plugins of socket close. We block since plugins // Fire proxy close event to notify plugins of socket close. We block since plugins
// should have a chance to be notified before the server stops accepting connections. // should have a chance to be notified before the server stops accepting connections.
server.getEventManager().fire(new ListenerClosedEvent(oldBind, endpoint.getType())).join(); server.getEventManager().fire(new ListenerClosedEventImpl(oldBind, endpoint.getType())).join();
Channel serverChannel = endpoint.getChannel(); Channel serverChannel = endpoint.getChannel();
@ -222,7 +222,7 @@ public final class ConnectionManager {
// Fire proxy close event to notify plugins of socket close. We block since plugins // Fire proxy close event to notify plugins of socket close. We block since plugins
// should have a chance to be notified before the server stops accepting connections. // should have a chance to be notified before the server stops accepting connections.
server.getEventManager().fire(new ListenerClosedEvent(address, endpoint.getType())).join(); server.getEventManager().fire(new ListenerClosedEventImpl(address, endpoint.getType())).join();
try { try {
LOGGER.info("Closing endpoint {}", address); LOGGER.info("Closing endpoint {}", address);

Datei anzeigen

@ -23,7 +23,7 @@ import static com.velocitypowered.api.event.connection.ProxyQueryEvent.QueryType
import com.google.common.cache.Cache; import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.velocitypowered.api.event.connection.ProxyQueryEvent; import com.velocitypowered.api.event.connection.ProxyQueryEventImpl;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.plugin.PluginContainer; import com.velocitypowered.api.plugin.PluginContainer;
import com.velocitypowered.api.plugin.PluginDescription; import com.velocitypowered.api.plugin.PluginDescription;
@ -151,7 +151,7 @@ public class GS4QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
// Call event and write response // Call event and write response
server.getEventManager() server.getEventManager()
.fire(new ProxyQueryEvent(isBasic ? BASIC : FULL, senderAddress, response)) .fire(new ProxyQueryEventImpl(isBasic ? BASIC : FULL, senderAddress, response))
.whenCompleteAsync((event, exc) -> { .whenCompleteAsync((event, exc) -> {
// Packet header // Packet header
ByteBuf queryResponse = ctx.alloc().buffer(); ByteBuf queryResponse = ctx.alloc().buffer();