2012-10-10 22:18:11 +02:00
|
|
|
/*
|
|
|
|
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
|
|
|
|
* Copyright (C) 2012 Kristian S. Stangeland
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2012-09-29 01:00:12 +02:00
|
|
|
package com.comphenix.protocol.injector;
|
|
|
|
|
2012-09-29 18:05:08 +02:00
|
|
|
import java.util.Collection;
|
2012-09-29 01:00:12 +02:00
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
import com.comphenix.protocol.concurrency.AbstractConcurrentListenerMultimap;
|
|
|
|
import com.comphenix.protocol.events.PacketAdapter;
|
|
|
|
import com.comphenix.protocol.events.PacketEvent;
|
|
|
|
import com.comphenix.protocol.events.PacketListener;
|
|
|
|
|
|
|
|
/**
|
2012-09-29 18:05:08 +02:00
|
|
|
* Registry of synchronous packet listeners.
|
2012-09-29 01:00:12 +02:00
|
|
|
*
|
|
|
|
* @author Kristian
|
|
|
|
*/
|
|
|
|
class SortedPacketListenerList extends AbstractConcurrentListenerMultimap<PacketListener> {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invokes the given packet event for every registered listener.
|
|
|
|
* @param logger - the logger that will be used to inform about listener exceptions.
|
|
|
|
* @param event - the packet event to invoke.
|
|
|
|
*/
|
|
|
|
public void invokePacketRecieving(Logger logger, PacketEvent event) {
|
2012-09-29 18:05:08 +02:00
|
|
|
Collection<PrioritizedListener<PacketListener>> list = getListener(event.getPacketID());
|
2012-09-29 01:00:12 +02:00
|
|
|
|
|
|
|
if (list == null)
|
|
|
|
return;
|
2012-09-29 18:05:08 +02:00
|
|
|
|
|
|
|
// The returned list is thread-safe
|
|
|
|
for (PrioritizedListener<PacketListener> element : list) {
|
|
|
|
try {
|
|
|
|
element.getListener().onPacketReceiving(event);
|
|
|
|
} catch (Throwable e) {
|
|
|
|
// Minecraft doesn't want your Exception.
|
|
|
|
logger.log(Level.SEVERE,
|
|
|
|
"Exception occured in onPacketReceiving() for " +
|
|
|
|
PacketAdapter.getPluginName(element.getListener()), e);
|
2012-09-29 01:00:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invokes the given packet event for every registered listener.
|
|
|
|
* @param logger - the logger that will be used to inform about listener exceptions.
|
|
|
|
* @param event - the packet event to invoke.
|
|
|
|
*/
|
|
|
|
public void invokePacketSending(Logger logger, PacketEvent event) {
|
2012-09-29 18:05:08 +02:00
|
|
|
Collection<PrioritizedListener<PacketListener>> list = getListener(event.getPacketID());
|
2012-09-29 01:00:12 +02:00
|
|
|
|
|
|
|
if (list == null)
|
|
|
|
return;
|
|
|
|
|
2012-09-29 18:05:08 +02:00
|
|
|
for (PrioritizedListener<PacketListener> element : list) {
|
|
|
|
try {
|
|
|
|
element.getListener().onPacketSending(event);
|
|
|
|
} catch (Throwable e) {
|
|
|
|
// Minecraft doesn't want your Exception.
|
|
|
|
logger.log(Level.SEVERE,
|
2012-10-01 02:17:13 +02:00
|
|
|
"Exception occured in onPacketSending() for " +
|
2012-09-29 18:05:08 +02:00
|
|
|
PacketAdapter.getPluginName(element.getListener()), e);
|
2012-09-29 01:00:12 +02:00
|
|
|
}
|
2012-09-29 18:05:08 +02:00
|
|
|
}
|
2012-09-29 01:00:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|