2012-10-16 07:28:54 +02:00
|
|
|
/*
|
|
|
|
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
|
|
|
|
* Copyright (C) 2012 Kristian S. Stangeland
|
|
|
|
*
|
2015-06-17 20:25:39 +02:00
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 2 of
|
2012-10-16 07:28:54 +02:00
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
2015-06-17 20:25:39 +02:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
2012-10-16 07:28:54 +02:00
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
2015-06-17 20:25:39 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along with this program;
|
|
|
|
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
2012-10-16 07:28:54 +02:00
|
|
|
* 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.comphenix.protocol;
|
|
|
|
|
2012-11-21 02:48:14 +01:00
|
|
|
import java.lang.reflect.InvocationTargetException;
|
2012-10-16 07:28:54 +02:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2013-09-02 02:42:18 +02:00
|
|
|
import org.bukkit.Location;
|
2012-11-13 16:10:56 +01:00
|
|
|
import org.bukkit.World;
|
2012-10-16 07:28:54 +02:00
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.plugin.Plugin;
|
|
|
|
|
2012-11-21 02:48:14 +01:00
|
|
|
import com.comphenix.protocol.async.AsyncMarker;
|
2013-03-12 01:16:07 +01:00
|
|
|
import com.comphenix.protocol.events.ListenerPriority;
|
2016-03-19 21:01:38 +01:00
|
|
|
import com.comphenix.protocol.events.ListeningWhitelist;
|
2012-10-16 07:28:54 +02:00
|
|
|
import com.comphenix.protocol.events.PacketContainer;
|
|
|
|
import com.comphenix.protocol.events.PacketListener;
|
|
|
|
import com.comphenix.protocol.injector.PacketConstructor;
|
|
|
|
import com.comphenix.protocol.reflect.FieldAccessException;
|
2013-07-19 21:22:34 +02:00
|
|
|
import com.comphenix.protocol.utility.MinecraftVersion;
|
2012-10-16 07:28:54 +02:00
|
|
|
import com.google.common.collect.ImmutableSet;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents an API for accessing the Minecraft protocol.
|
|
|
|
* @author Kristian
|
|
|
|
*/
|
|
|
|
public interface ProtocolManager extends PacketStream {
|
2014-09-05 01:57:29 +02:00
|
|
|
/**
|
|
|
|
* Retrieve the protocol version of a given player.
|
|
|
|
* <p>
|
|
|
|
* This only really makes sense of a server that support clients of multiple Minecraft versions, such as Spigot #1628.
|
|
|
|
* @param player - the player.
|
|
|
|
* @return The associated protocol version, or {@link Integer#MIN_VALUE} if unknown.
|
|
|
|
*/
|
|
|
|
public int getProtocolVersion(Player player);
|
|
|
|
|
2012-11-21 02:48:14 +01:00
|
|
|
/**
|
|
|
|
* Send a packet to the given player.
|
|
|
|
* <p>
|
2015-06-17 20:25:39 +02:00
|
|
|
* Re-sending a previously cancelled packet is discouraged. Use {@link AsyncMarker#incrementProcessingDelay()}
|
2012-11-21 02:48:14 +01:00
|
|
|
* to delay a packet until a certain condition has been met.
|
|
|
|
*
|
2013-12-05 21:24:31 +01:00
|
|
|
* @param receiver - the receiver.
|
2012-11-21 02:48:14 +01:00
|
|
|
* @param packet - packet to send.
|
2013-03-12 01:16:07 +01:00
|
|
|
* @param filters - whether or not to invoke any packet filters below {@link ListenerPriority#MONITOR}.
|
2013-12-05 21:24:31 +01:00
|
|
|
* @throws InvocationTargetException - if an error occurred when sending the packet.
|
2012-11-21 02:48:14 +01:00
|
|
|
*/
|
|
|
|
@Override
|
2015-06-17 20:25:39 +02:00
|
|
|
public void sendServerPacket(Player receiver, PacketContainer packet, boolean filters)
|
2012-11-21 02:48:14 +01:00
|
|
|
throws InvocationTargetException;
|
|
|
|
|
|
|
|
/**
|
2013-12-05 21:24:31 +01:00
|
|
|
* Simulate receiving a certain packet from a given player.
|
2012-11-21 02:48:14 +01:00
|
|
|
* <p>
|
2015-06-17 20:25:39 +02:00
|
|
|
* Receiving a previously cancelled packet is discouraged. Use {@link AsyncMarker#incrementProcessingDelay()}
|
2012-11-21 02:48:14 +01:00
|
|
|
* to delay a packet until a certain condition has been met.
|
|
|
|
*
|
|
|
|
* @param sender - the sender.
|
|
|
|
* @param packet - the packet that was sent.
|
2013-03-12 01:16:07 +01:00
|
|
|
* @param filters - whether or not to invoke any packet filters below {@link ListenerPriority#MONITOR}.
|
2012-11-21 02:48:14 +01:00
|
|
|
* @throws InvocationTargetException If the reflection machinery failed.
|
|
|
|
* @throws IllegalAccessException If the underlying method caused an error.
|
|
|
|
*/
|
|
|
|
@Override
|
2015-06-17 20:25:39 +02:00
|
|
|
public void recieveClientPacket(Player sender, PacketContainer packet, boolean filters)
|
2012-11-21 02:48:14 +01:00
|
|
|
throws IllegalAccessException, InvocationTargetException;
|
|
|
|
|
2013-09-01 18:47:24 +02:00
|
|
|
/**
|
|
|
|
* Broadcast a given packet to every connected player on the server.
|
|
|
|
* @param packet - the packet to broadcast.
|
|
|
|
* @throws FieldAccessException If we were unable to send the packet due to reflection problems.
|
|
|
|
*/
|
|
|
|
public void broadcastServerPacket(PacketContainer packet);
|
|
|
|
|
|
|
|
/**
|
2015-06-17 20:25:39 +02:00
|
|
|
* Broadcast a packet to every player that is receiving information about a given entity.
|
2013-09-01 18:47:24 +02:00
|
|
|
* <p>
|
2015-06-17 20:25:39 +02:00
|
|
|
* This is usually every player in the same world within an observable distance. If the entity is a
|
2013-09-02 02:42:18 +02:00
|
|
|
* player, it will only be included if <i>includeTracker</i> is TRUE.
|
2013-09-01 18:47:24 +02:00
|
|
|
* @param packet - the packet to broadcast.
|
2013-09-02 02:42:18 +02:00
|
|
|
* @param entity - the entity whose trackers we will inform.
|
|
|
|
* @param includeTracker - whether or not to also transmit the packet to the entity, if it is a tracker.
|
2013-09-01 18:47:24 +02:00
|
|
|
* @throws FieldAccessException If we were unable to send the packet due to reflection problems.
|
|
|
|
*/
|
2013-09-02 02:42:18 +02:00
|
|
|
public void broadcastServerPacket(PacketContainer packet, Entity entity, boolean includeTracker);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Broadcast a packet to every player within the given maximum observer distance.
|
|
|
|
* @param packet - the packet to broadcast.
|
|
|
|
* @param origin - the origin to consider when calculating the distance to each observer.
|
|
|
|
* @param maxObserverDistance - the maximum distance to the origin.
|
|
|
|
*/
|
|
|
|
public void broadcastServerPacket(PacketContainer packet, Location origin, int maxObserverDistance);
|
2013-09-01 18:47:24 +02:00
|
|
|
|
2012-10-16 07:28:54 +02:00
|
|
|
/**
|
|
|
|
* Retrieves a list of every registered packet listener.
|
|
|
|
* @return Every registered packet listener.
|
|
|
|
*/
|
|
|
|
public ImmutableSet<PacketListener> getPacketListeners();
|
|
|
|
|
|
|
|
/**
|
2015-06-17 20:25:39 +02:00
|
|
|
* Adds a packet listener.
|
2012-10-16 07:28:54 +02:00
|
|
|
* <p>
|
2015-06-17 20:25:39 +02:00
|
|
|
* Adding an already registered listener has no effect. If you need to change the packets
|
|
|
|
* the current listener is observing, you must first remove the packet listener before you
|
2012-10-16 07:28:54 +02:00
|
|
|
* can register it again.
|
|
|
|
* @param listener - new packet listener.
|
|
|
|
*/
|
|
|
|
public void addPacketListener(PacketListener listener);
|
|
|
|
|
|
|
|
/**
|
2015-06-17 20:25:39 +02:00
|
|
|
* Removes a given packet listener.
|
2012-10-16 07:28:54 +02:00
|
|
|
* <p>
|
|
|
|
* Attempting to remove a listener that doesn't exist has no effect.
|
|
|
|
* @param listener - the packet listener to remove.
|
|
|
|
*/
|
|
|
|
public void removePacketListener(PacketListener listener);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes every listener associated with the given plugin.
|
|
|
|
* @param plugin - the plugin to unload.
|
|
|
|
*/
|
|
|
|
public void removePacketListeners(Plugin plugin);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs a new encapsulated Minecraft packet with the given ID.
|
2013-12-05 06:52:20 +01:00
|
|
|
* <p>
|
|
|
|
* Deprecated: Use {@link #createPacket(PacketType)} instead.
|
2012-10-16 07:28:54 +02:00
|
|
|
* @param id - packet ID.
|
|
|
|
* @return New encapsulated Minecraft packet.
|
|
|
|
*/
|
2013-12-05 06:52:20 +01:00
|
|
|
@Deprecated
|
2012-10-16 07:28:54 +02:00
|
|
|
public PacketContainer createPacket(int id);
|
|
|
|
|
2013-12-05 06:52:20 +01:00
|
|
|
/**
|
|
|
|
* Constructs a new encapsulated Minecraft packet with the given ID.
|
|
|
|
* @param type - packet type.
|
|
|
|
* @return New encapsulated Minecraft packet.
|
|
|
|
*/
|
|
|
|
public PacketContainer createPacket(PacketType type);
|
|
|
|
|
2012-10-16 07:28:54 +02:00
|
|
|
/**
|
|
|
|
* Constructs a new encapsulated Minecraft packet with the given ID.
|
|
|
|
* <p>
|
2015-06-17 20:25:39 +02:00
|
|
|
* If set to true, the <i>forceDefaults</i> option will force the system to automatically
|
2012-10-16 07:28:54 +02:00
|
|
|
* give non-primitive fields in the packet sensible default values. For instance, certain
|
|
|
|
* packets - like Packet60Explosion - require a List or Set to be non-null. If the
|
|
|
|
* forceDefaults option is true, the List or Set will be automatically created.
|
2013-12-05 06:52:20 +01:00
|
|
|
* <p>
|
|
|
|
* Deprecated: Use {@link #createPacket(PacketType, boolean)} instead.
|
2012-10-16 07:28:54 +02:00
|
|
|
*
|
|
|
|
* @param id - packet ID.
|
|
|
|
* @param forceDefaults - TRUE to use sensible defaults in most fields, FALSE otherwise.
|
|
|
|
* @return New encapsulated Minecraft packet.
|
|
|
|
*/
|
2013-12-05 06:52:20 +01:00
|
|
|
@Deprecated
|
2012-10-16 07:28:54 +02:00
|
|
|
public PacketContainer createPacket(int id, boolean forceDefaults);
|
2013-12-05 06:52:20 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs a new encapsulated Minecraft packet with the given ID.
|
|
|
|
* <p>
|
2015-06-17 20:25:39 +02:00
|
|
|
* If set to true, the <i>forceDefaults</i> option will force the system to automatically
|
2013-12-05 06:52:20 +01:00
|
|
|
* give non-primitive fields in the packet sensible default values. For instance, certain
|
|
|
|
* packets - like Packet60Explosion - require a List or Set to be non-null. If the
|
|
|
|
* forceDefaults option is true, the List or Set will be automatically created.
|
|
|
|
*
|
|
|
|
* @param type - packet type.
|
|
|
|
* @param forceDefaults - TRUE to use sensible defaults in most fields, FALSE otherwise.
|
|
|
|
* @return New encapsulated Minecraft packet.
|
|
|
|
*/
|
|
|
|
public PacketContainer createPacket(PacketType type, boolean forceDefaults);
|
2012-10-16 07:28:54 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct a packet using the special builtin Minecraft constructors.
|
2013-12-05 03:54:17 +01:00
|
|
|
* <p>
|
|
|
|
* Deprecated: Use {@link #createPacketConstructor(PacketType, Object...)} instead.
|
2012-10-16 07:28:54 +02:00
|
|
|
* @param id - the packet ID.
|
|
|
|
* @param arguments - arguments that will be passed to the constructor.
|
|
|
|
* @return The packet constructor.
|
|
|
|
*/
|
2013-12-05 03:54:17 +01:00
|
|
|
@Deprecated
|
2012-10-16 07:28:54 +02:00
|
|
|
public PacketConstructor createPacketConstructor(int id, Object... arguments);
|
|
|
|
|
2013-12-05 03:54:17 +01:00
|
|
|
/**
|
|
|
|
* Construct a packet using the special builtin Minecraft constructors.
|
2015-06-17 20:25:39 +02:00
|
|
|
* @param type - the packet type.
|
2013-12-05 03:54:17 +01:00
|
|
|
* @param arguments - arguments that will be passed to the constructor.
|
|
|
|
* @return The packet constructor.
|
|
|
|
*/
|
|
|
|
public PacketConstructor createPacketConstructor(PacketType type, Object... arguments);
|
|
|
|
|
2012-10-16 07:28:54 +02:00
|
|
|
/**
|
2012-12-02 02:49:11 +01:00
|
|
|
* Completely resend an entity to a list of clients.
|
2012-10-16 07:28:54 +02:00
|
|
|
* <p>
|
2015-06-17 20:25:39 +02:00
|
|
|
* Note that this method is NOT thread safe. If you call this method from anything
|
2012-10-16 07:28:54 +02:00
|
|
|
* but the main thread, it will throw an exception.
|
|
|
|
* @param entity - entity to refresh.
|
|
|
|
* @param observers - the clients to update.
|
|
|
|
*/
|
|
|
|
public void updateEntity(Entity entity, List<Player> observers) throws FieldAccessException;
|
|
|
|
|
2012-11-13 16:10:56 +01:00
|
|
|
/**
|
|
|
|
* Retrieve the associated entity.
|
|
|
|
* @param container - the world the entity belongs to.
|
|
|
|
* @param id - the unique ID of the entity.
|
|
|
|
* @return The associated entity.
|
|
|
|
* @throws FieldAccessException Reflection failed.
|
|
|
|
*/
|
|
|
|
public Entity getEntityFromID(World container, int id) throws FieldAccessException;
|
|
|
|
|
2012-12-02 02:49:11 +01:00
|
|
|
/**
|
|
|
|
* Retrieve every client that is receiving information about a given entity.
|
|
|
|
* @param entity - the entity that is being tracked.
|
|
|
|
* @return Every client/player that is tracking the given entity.
|
|
|
|
* @throws FieldAccessException If reflection failed.
|
|
|
|
*/
|
|
|
|
public List<Player> getEntityTrackers(Entity entity) throws FieldAccessException;
|
|
|
|
|
2012-10-16 07:28:54 +02:00
|
|
|
/**
|
|
|
|
* Retrieves a immutable set containing the ID of the sent server packets that will be observed by listeners.
|
2013-12-05 06:52:20 +01:00
|
|
|
* <p>
|
|
|
|
* Deprecated: Use {@link #getSendingFilterTypes()} instead.
|
2012-10-16 07:28:54 +02:00
|
|
|
* @return Every filtered server packet.
|
|
|
|
*/
|
2013-12-05 06:52:20 +01:00
|
|
|
@Deprecated
|
2012-10-16 07:28:54 +02:00
|
|
|
public Set<Integer> getSendingFilters();
|
|
|
|
|
2013-12-05 06:52:20 +01:00
|
|
|
/**
|
|
|
|
* Retrieves a immutable set containing the type of the sent server packets that will be observed by listeners.
|
|
|
|
* @return Every filtered server packet.
|
|
|
|
*/
|
|
|
|
public Set<PacketType> getSendingFilterTypes();
|
|
|
|
|
2012-10-16 07:28:54 +02:00
|
|
|
/**
|
2013-12-05 21:24:31 +01:00
|
|
|
* Retrieves a immutable set containing the ID of the received client packets that will be observed by listeners.
|
2013-12-05 06:52:20 +01:00
|
|
|
* <p>
|
|
|
|
* Deprecated: Use {@link #getReceivingFilterTypes()} instead.
|
2012-10-16 07:28:54 +02:00
|
|
|
* @return Every filtered client packet.
|
|
|
|
*/
|
2013-12-05 06:52:20 +01:00
|
|
|
@Deprecated
|
2012-10-16 07:28:54 +02:00
|
|
|
public Set<Integer> getReceivingFilters();
|
|
|
|
|
2013-12-05 06:52:20 +01:00
|
|
|
/**
|
2013-12-05 21:24:31 +01:00
|
|
|
* Retrieves a immutable set containing the type of the received client packets that will be observed by listeners.
|
2013-12-05 06:52:20 +01:00
|
|
|
* @return Every filtered client packet.
|
|
|
|
*/
|
|
|
|
public Set<PacketType> getReceivingFilterTypes();
|
|
|
|
|
2013-07-19 21:22:34 +02:00
|
|
|
/**
|
|
|
|
* Retrieve the current Minecraft version.
|
|
|
|
* @return The current version.
|
|
|
|
*/
|
|
|
|
public MinecraftVersion getMinecraftVersion();
|
|
|
|
|
2012-10-16 07:28:54 +02:00
|
|
|
/**
|
2015-06-17 20:25:39 +02:00
|
|
|
* Determines whether or not this protocol manager has been disabled.
|
2012-10-16 07:28:54 +02:00
|
|
|
* @return TRUE if it has, FALSE otherwise.
|
|
|
|
*/
|
|
|
|
public boolean isClosed();
|
|
|
|
|
|
|
|
/**
|
2013-12-05 21:24:31 +01:00
|
|
|
* Retrieve the current asynchronous packet manager.
|
|
|
|
* @return Asynchronous packet manager.
|
2012-10-16 07:28:54 +02:00
|
|
|
*/
|
|
|
|
public AsynchronousManager getAsynchronousManager();
|
2016-03-19 21:01:38 +01:00
|
|
|
|
|
|
|
public void verifyWhitelist(PacketListener listener, ListeningWhitelist whitelist);
|
2012-09-12 19:04:53 +02:00
|
|
|
}
|