Archiviert
13
0

Properly cancel written packets.

Dieser Commit ist enthalten in:
Kristian S. Stangeland 2013-12-05 21:27:22 +01:00
Ursprung be6d4fb720
Commit 29d71e05e4
4 geänderte Dateien mit 41 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -9,6 +9,7 @@ import java.util.concurrent.Future;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import com.comphenix.protocol.events.ConnectionSide;
import com.comphenix.protocol.injector.packet.PacketRegistry; import com.comphenix.protocol.injector.packet.PacketRegistry;
import com.comphenix.protocol.reflect.ObjectEnum; import com.comphenix.protocol.reflect.ObjectEnum;
import com.comphenix.protocol.utility.MinecraftVersion; import com.comphenix.protocol.utility.MinecraftVersion;
@ -376,7 +377,15 @@ public class PacketType implements Serializable {
/** /**
* Indicate that packets of this type will be sent by the current server. * Indicate that packets of this type will be sent by the current server.
*/ */
SERVER SERVER;
/**
* Retrieve the equivialent connection side.
* @return The connection side.
*/
public ConnectionSide toSide() {
return this == CLIENT ? ConnectionSide.CLIENT_SIDE : ConnectionSide.SERVER_SIDE;
}
} }
// Lookup of packet types // Lookup of packet types

Datei anzeigen

@ -55,6 +55,26 @@ public abstract class PacketAdapter implements PacketListener {
); );
} }
/**
* Initialize a packet listener with the given parameters.
* @param plugin - the plugin.
* @param listenerPriority - the priority.
* @param types - the packet types.
*/
public PacketAdapter(Plugin plugin, PacketType... types) {
this(plugin, ListenerPriority.NORMAL, types);
}
/**
* Initialize a packet listener with the given parameters.
* @param plugin - the plugin.
* @param listenerPriority - the priority.
* @param types - the packet types.
*/
public PacketAdapter(Plugin plugin, ListenerPriority listenerPriority, PacketType... types) {
this(params(plugin, types).listenerPriority(listenerPriority));
}
/** /**
* Initialize a packet listener with default priority. * Initialize a packet listener with default priority.
* <p> * <p>
@ -500,6 +520,12 @@ public abstract class PacketAdapter implements PacketListener {
* @return This builder, for chaining. * @return This builder, for chaining.
*/ */
public AdapterParameteters types(@Nonnull PacketType... packets) { public AdapterParameteters types(@Nonnull PacketType... packets) {
// Set the connection side as well
if (connectionSide == null) {
for (PacketType type : packets) {
this.connectionSide = ConnectionSide.add(this.connectionSide, type.getSender().toSide());
}
}
this.packets = Preconditions.checkNotNull(packets, "packets cannot be NULL"); this.packets = Preconditions.checkNotNull(packets, "packets cannot be NULL");
return this; return this;
} }

Datei anzeigen

@ -45,14 +45,15 @@ abstract class ChannelProxy implements Channel {
(Class<? extends ChannelFuture>) ChannelProxy.class.getClassLoader(). (Class<? extends ChannelFuture>) ChannelProxy.class.getClassLoader().
loadClass("net.minecraft.util.io.netty.channel.SucceededChannelFuture"); loadClass("net.minecraft.util.io.netty.channel.SucceededChannelFuture");
FUTURE_CONSTRUCTOR = succededFuture.getConstructor(Channel.class, EventExecutor.class); FUTURE_CONSTRUCTOR = succededFuture.getDeclaredConstructor(Channel.class, EventExecutor.class);
FUTURE_CONSTRUCTOR.setAccessible(true);
} }
return FUTURE_CONSTRUCTOR.newInstance(this, null); return FUTURE_CONSTRUCTOR.newInstance(this, null);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
throw new RuntimeException("Cannot get succeeded future."); throw new RuntimeException("Cannot get succeeded future.", e);
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("Cannot construct completed future."); throw new RuntimeException("Cannot construct completed future.", e);
} }
} }

Datei anzeigen

@ -298,7 +298,7 @@ public class PacketRegistry {
* @return Set of packet types. * @return Set of packet types.
*/ */
public static Set<PacketType> toPacketTypes(Set<Integer> ids) { public static Set<PacketType> toPacketTypes(Set<Integer> ids) {
return toPacketTypes(ids); return toPacketTypes(ids, null);
} }
/** /**