package com.gmail.woodyc40.common.protocol; import com.gmail.woodyc40.common.protocol.events.ProtocolEvent; import com.gmail.woodyc40.common.protocol.impl.ManagementImpl; import net.tridentsdk.entity.living.Player; import javax.annotation.concurrent.ThreadSafe; import java.util.Collection; /** * Manages the protocol * * <p>To obtain the instance of this manager, use this code: * <br/> * {@code ProtocolManagement management = ProtocolManagement.manager();}</p> * * <p>All methods in this class are thread-safe</p> * * @author Pierre C */ @ThreadSafe public interface ProtocolManagement { /** The management implementation instance */ static final ProtocolManagement MANAGEMENT = new ManagementImpl(); /** * Obtains the manager singleton, the only way to acquire it * * @return the manager implementation singleton */ public static ProtocolManagement manager() { return MANAGEMENT; } /** * Adds a listener for a particular protocol event to the pipeline * * @param listener the listener to add * @param <T> the type of event to listen for */ <T extends ProtocolEvent> void intercept(ProtocolListener<T> listener); /** * Deploy the event along the pipeline, with an optional action * * @param event the event to transmit * @param action the action to perform before transmitting the event */ <T extends ProtocolEvent> T transmit(T event, ProtocolAction action); /** * Removes the listener from the map * * @param listener the listener to remove */ <T extends ProtocolEvent> void remove(ProtocolListener<T> listener); /** * Sends a protocol action * * @param action the protocol action to perform */ void send(ProtocolAction action); /** * Sends the bytes in the appender to the players specified * * @param appender the appender to use bytes from * @param players the players to send the bytes to */ void send(ByteAppender appender, Collection<Player> players); /** * Sends the protocol action to all CURRENT online players * * @param action the action to send */ void sendAll(ProtocolAction action); /** * Creates a new packet creator * * @param id the id of the new packet (see wiki.vg) * @param out {@code true} to indicate the packet selected is clientbound, {@code false} for serverbound * @return the packet for the ID */ Packet createPacket(int id, boolean out); }