From 51c645928f6fa3061371fdfca4e11b218a06a88f Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Fri, 19 Jul 2013 19:47:22 +0200 Subject: [PATCH] Make it possible to specify optionIntercept() when using BOTH. --- .../protocol/events/PacketAdapter.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketAdapter.java b/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketAdapter.java index c07fb9c4..5db2bdf8 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketAdapter.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketAdapter.java @@ -17,6 +17,7 @@ package com.comphenix.protocol.events; +import java.util.List; import java.util.Set; import javax.annotation.Nonnull; @@ -25,6 +26,7 @@ import org.bukkit.plugin.Plugin; import com.comphenix.protocol.injector.GamePhase; import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; /** * Represents a packet listener with useful constructors. @@ -171,16 +173,33 @@ public abstract class PacketAdapter implements PacketListener { if (options == null) throw new IllegalArgumentException("options cannot be null"); + ListenerOptions[] serverOptions = options; + ListenerOptions[] clientOptions = options; + + // Special case that allows us to specify optionIntercept(). + if (connectionSide == ConnectionSide.BOTH) { + serverOptions = except(serverOptions, new ListenerOptions[0], + ListenerOptions.INTERCEPT_INPUT_BUFFER); + } + // Add whitelists if (connectionSide.isForServer()) - sendingWhitelist = new ListeningWhitelist(listenerPriority, packets, gamePhase, options); + sendingWhitelist = new ListeningWhitelist(listenerPriority, packets, gamePhase, serverOptions); if (connectionSide.isForClient()) - receivingWhitelist = new ListeningWhitelist(listenerPriority, packets, gamePhase, options); + receivingWhitelist = new ListeningWhitelist(listenerPriority, packets, gamePhase, clientOptions); this.plugin = plugin; this.connectionSide = connectionSide; } + // Remove a given element from an array + private static T[] except(T[] values, T[] buffer, T except) { + List result = Lists.newArrayList(values); + + result.remove(except); + return result.toArray(buffer); + } + @Override public void onPacketReceiving(PacketEvent event) { // Lets prevent some bugs