use of com.bergerkiller.bukkit.common.protocol.PacketMonitor in project BKCommonLib by bergerhealer.
the class PacketHandlerHooked method removePacketListeners.
@Override
public void removePacketListeners(Plugin plugin) {
// Listeners
List<PacketListener> listeners = listenerPlugins.get(plugin);
if (listeners != null) {
for (PacketListener listener : listeners) {
removePacketListener(listener, false);
}
}
// Monitors
List<PacketMonitor> monitors = monitorPlugins.get(plugin);
if (monitors != null) {
for (PacketMonitor monitor : monitors) {
removePacketMonitor(monitor, false);
}
}
}
use of com.bergerkiller.bukkit.common.protocol.PacketMonitor in project BKCommonLib by bergerhealer.
the class PacketHandlerHooked method addPacketMonitor.
@Override
public void addPacketMonitor(Plugin plugin, PacketMonitor monitor, PacketType[] types) {
if (monitor == null) {
throw new IllegalArgumentException("Monitor is not allowed to be null");
} else if (plugin == null) {
throw new IllegalArgumentException("Plugin is not allowed to be null");
}
// Register the listener
for (PacketType type : types) {
// Map to listener array
List<PacketMonitor> monitorList = monitors.get(type);
if (monitorList == null) {
monitorList = new ArrayList<PacketMonitor>();
monitors.put(type, monitorList);
}
monitorList.add(monitor);
// Map to plugin list
List<PacketMonitor> list = monitorPlugins.get(plugin);
if (list == null) {
list = new ArrayList<PacketMonitor>(2);
monitorPlugins.put(plugin, list);
}
list.add(monitor);
}
}
use of com.bergerkiller.bukkit.common.protocol.PacketMonitor in project BKCommonLib by bergerhealer.
the class PacketHandlerHooked method handlePacketReceive.
/**
* Handles a packet before it is being handled by the server
*
* @param player from which the packet came
* @param packet that is handled
* @param wasCancelled - True if the packet is allowed to be received, False
* if not
* @return True if the packet is allowed to be received, False if not
*/
public boolean handlePacketReceive(Player player, Object packet, boolean wasCancelled) {
if (player == null || packet == null) {
return true;
}
// Handle listeners
PacketType type = PacketType.getType(packet);
List<PacketListener> listenerList = listeners.get(type);
if (listenerList != null) {
CommonPacket cp = new CommonPacket(packet, type);
PacketReceiveEvent ev = new PacketReceiveEvent(player, cp);
ev.setCancelled(wasCancelled);
for (PacketListener listener : listenerList) {
try {
listener.onPacketReceive(ev);
} catch (Throwable t) {
Logging.LOGGER_NETWORK.log(Level.SEVERE, "Error occurred in onPacketReceive handling " + type + ":", t);
}
}
if (ev.isCancelled()) {
return false;
}
}
// Handle monitors
List<PacketMonitor> monitorList = monitors.get(type);
if (monitorList != null) {
CommonPacket cp = new CommonPacket(packet, type);
for (PacketMonitor monitor : monitorList) {
try {
monitor.onMonitorPacketReceive(cp, player);
} catch (Throwable t) {
Logging.LOGGER_NETWORK.log(Level.SEVERE, "Error occurred in onMonitorPacketReceive handling " + type + ":", t);
}
}
}
return true;
}
Aggregations