2021-03-23 11:51:40 +01:00
|
|
|
/*
|
|
|
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
2023-01-12 12:45:53 +01:00
|
|
|
* Copyright (C) 2016-2023 ViaVersion and contributors
|
2021-03-23 11:51:40 +01:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
2021-04-26 20:52:34 +02:00
|
|
|
package com.viaversion.viaversion.api.protocol;
|
2016-03-14 19:05:29 +01:00
|
|
|
|
2021-04-26 21:35:29 +02:00
|
|
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
2021-04-28 12:59:37 +02:00
|
|
|
import java.util.Collection;
|
2016-03-17 22:24:25 +01:00
|
|
|
import java.util.List;
|
2023-02-12 11:44:25 +01:00
|
|
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
2016-03-14 19:05:29 +01:00
|
|
|
|
2021-04-26 22:54:43 +02:00
|
|
|
public interface ProtocolPipeline extends SimpleProtocol {
|
2016-03-14 19:05:29 +01:00
|
|
|
|
2016-03-22 19:02:46 +01:00
|
|
|
/**
|
2021-04-21 11:58:19 +02:00
|
|
|
* Adds a protocol to the current pipeline.
|
2018-07-14 14:11:17 +02:00
|
|
|
* This will call the {@link Protocol#init(UserConnection)} method.
|
2016-03-22 19:02:46 +01:00
|
|
|
*
|
2021-04-21 11:58:19 +02:00
|
|
|
* @param protocol protocol to add to the end
|
2016-03-22 19:02:46 +01:00
|
|
|
*/
|
2021-04-26 22:54:43 +02:00
|
|
|
void add(Protocol protocol);
|
2021-04-21 11:58:19 +02:00
|
|
|
|
|
|
|
/**
|
2021-04-28 12:59:37 +02:00
|
|
|
* Adds a collection of protocols to the current pipeline.
|
2021-04-21 11:58:19 +02:00
|
|
|
* This will call the {@link Protocol#init(UserConnection)} method.
|
2021-04-28 12:59:37 +02:00
|
|
|
* <p>
|
|
|
|
* Callers of this method should make sure the collection is correctly sorted.
|
2021-04-21 11:58:19 +02:00
|
|
|
*
|
2021-04-28 12:59:37 +02:00
|
|
|
* @param protocols correctly sorted protocols to add to the end
|
2021-04-21 11:58:19 +02:00
|
|
|
*/
|
2021-04-28 12:59:37 +02:00
|
|
|
void add(Collection<Protocol> protocols);
|
2020-09-06 10:24:14 +02:00
|
|
|
|
2016-03-22 19:02:46 +01:00
|
|
|
/**
|
2021-04-27 15:56:34 +02:00
|
|
|
* Returns whether the protocol is in this pipeline.
|
2016-03-22 19:02:46 +01:00
|
|
|
*
|
2021-04-27 15:56:34 +02:00
|
|
|
* @param protocolClass protocol class
|
|
|
|
* @return whether the protocol class is in this pipeline
|
2016-03-22 19:02:46 +01:00
|
|
|
*/
|
2021-04-27 15:56:34 +02:00
|
|
|
boolean contains(Class<? extends Protocol> protocolClass);
|
2016-03-22 16:36:11 +01:00
|
|
|
|
2021-04-26 22:54:43 +02:00
|
|
|
/**
|
|
|
|
* Returns the protocol from the given class if present in the pipeline.
|
|
|
|
*
|
|
|
|
* @param pipeClass protocol class
|
|
|
|
* @param <P> protocol
|
|
|
|
* @return protocol from class
|
|
|
|
* @see #contains(Class)
|
2021-04-27 15:56:34 +02:00
|
|
|
* @see ProtocolManager#getProtocol(Class) for a faster implementation
|
2021-04-26 22:54:43 +02:00
|
|
|
*/
|
|
|
|
@Nullable <P extends Protocol> P getProtocol(Class<P> pipeClass);
|
2019-05-09 14:43:48 +02:00
|
|
|
|
2016-03-22 19:02:46 +01:00
|
|
|
/**
|
2021-04-27 15:56:34 +02:00
|
|
|
* Returns the list of protocols this pipeline contains.
|
2016-03-22 19:02:46 +01:00
|
|
|
*
|
2021-04-27 15:56:34 +02:00
|
|
|
* @return list of protocols in this pipe
|
2016-03-22 19:02:46 +01:00
|
|
|
*/
|
2021-04-27 15:56:34 +02:00
|
|
|
List<Protocol> pipes();
|
2016-05-17 23:48:56 +02:00
|
|
|
|
2021-04-27 10:29:30 +02:00
|
|
|
/**
|
2021-04-27 15:56:34 +02:00
|
|
|
* Returns whether this pipe has protocols that are not base protocols, as given by {@link Protocol#isBaseProtocol()}.
|
2021-04-27 10:29:30 +02:00
|
|
|
*
|
2021-04-27 15:56:34 +02:00
|
|
|
* @return whether this pipe has protocols that are not base protocols
|
2021-04-27 10:29:30 +02:00
|
|
|
*/
|
2021-04-27 15:56:34 +02:00
|
|
|
boolean hasNonBaseProtocols();
|
2016-10-01 00:53:50 +02:00
|
|
|
|
2018-07-14 14:11:17 +02:00
|
|
|
/**
|
2021-03-22 23:06:40 +01:00
|
|
|
* Cleans the pipe and adds the base protocol.
|
|
|
|
* /!\ WARNING - It doesn't add version-specific base Protocol.
|
2018-07-14 14:11:17 +02:00
|
|
|
*/
|
2021-04-26 22:54:43 +02:00
|
|
|
void cleanPipes();
|
2016-03-14 19:05:29 +01:00
|
|
|
}
|