All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.mayuna.timestop.networking.base.ConnectionContext Maven / Gradle / Ivy

package dev.mayuna.timestop.networking.base;

import com.esotericsoftware.kryonet.Connection;
import lombok.Getter;
import lombok.NonNull;

/**
 * Context for received/sent messages.
 */
@Getter
public class ConnectionContext {

    private final Connection connection;

    /**
     * Creates a new context
     *
     * @param connection Connection the message was received from / will be sent to
     */
    public ConnectionContext(@NonNull Connection connection) {
        this.connection = connection;
    }

    /**
     * Returns the connection as the given class. Throws a ClassCastException if the connection is not an instance of the given class.
     *
     * @param clazz Class
     * @param    Type
     *
     * @return Connection as the given class
     */
    public  T getConnectionAs(Class clazz) {
        return clazz.cast(connection);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy