mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-24 03:25:29 +01:00
Added a monitor every packet listener.
This commit is contained in:
parent
a173824b3f
commit
98ae5c6e29
@ -0,0 +1,75 @@
|
|||||||
|
package com.comphenix.protocol.events;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.Packets;
|
||||||
|
import com.comphenix.protocol.events.ConnectionSide;
|
||||||
|
import com.comphenix.protocol.events.ListenerPriority;
|
||||||
|
import com.comphenix.protocol.events.ListeningWhitelist;
|
||||||
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
|
import com.comphenix.protocol.events.PacketListener;
|
||||||
|
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a listener that is notified of every sent and recieved packet.
|
||||||
|
*
|
||||||
|
* @author Kristian
|
||||||
|
*/
|
||||||
|
public abstract class MonitorAdapter implements PacketListener {
|
||||||
|
|
||||||
|
private Plugin plugin;
|
||||||
|
private ListeningWhitelist sending = ListeningWhitelist.EMPTY_WHITELIST;
|
||||||
|
private ListeningWhitelist receiving = ListeningWhitelist.EMPTY_WHITELIST;
|
||||||
|
|
||||||
|
public MonitorAdapter(Plugin plugin, ConnectionSide side) {
|
||||||
|
this(plugin, side, plugin.getLogger());
|
||||||
|
}
|
||||||
|
|
||||||
|
public MonitorAdapter(Plugin plugin, ConnectionSide side, Logger logger) {
|
||||||
|
super();
|
||||||
|
this.plugin = plugin;
|
||||||
|
|
||||||
|
// Recover in case something goes wrong
|
||||||
|
try {
|
||||||
|
if (side.isForServer())
|
||||||
|
this.sending = new ListeningWhitelist(ListenerPriority.MONITOR, Packets.Server.getSupported());
|
||||||
|
if (side.isForClient())
|
||||||
|
this.receiving = new ListeningWhitelist(ListenerPriority.MONITOR, Packets.Client.getSupported());
|
||||||
|
} catch (FieldAccessException e) {
|
||||||
|
if (side.isForServer())
|
||||||
|
this.sending = new ListeningWhitelist(ListenerPriority.MONITOR, Packets.Server.getRegistry().values());
|
||||||
|
if (side.isForClient())
|
||||||
|
this.receiving = new ListeningWhitelist(ListenerPriority.MONITOR, Packets.Client.getRegistry().values());
|
||||||
|
logger.log(Level.WARNING, "Defaulting to 1.3 packets.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPacketReceiving(PacketEvent event) {
|
||||||
|
// Empty for now
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPacketSending(PacketEvent event) {
|
||||||
|
// Empty for now
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ListeningWhitelist getSendingWhitelist() {
|
||||||
|
return sending;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ListeningWhitelist getReceivingWhitelist() {
|
||||||
|
return receiving;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Plugin getPlugin() {
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
package com.comphenix.protocol.events;
|
package com.comphenix.protocol.events;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,6 +43,17 @@ public abstract class PacketAdapter implements PacketListener {
|
|||||||
this(plugin, connectionSide, ListenerPriority.NORMAL, packets);
|
this(plugin, connectionSide, ListenerPriority.NORMAL, packets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize a packet listener for a single connection side.
|
||||||
|
* @param plugin - the plugin that spawned this listener.
|
||||||
|
* @param connectionSide - the packet type the listener is looking for.
|
||||||
|
* @param listenerPriority - the event priority.
|
||||||
|
* @param packets - the packet IDs the listener is looking for.
|
||||||
|
*/
|
||||||
|
public PacketAdapter(Plugin plugin, ConnectionSide connectionSide, ListenerPriority listenerPriority, Set<Integer> packets) {
|
||||||
|
this(plugin, connectionSide, listenerPriority, packets.toArray(new Integer[0]));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize a packet listener for a single connection side.
|
* Initialize a packet listener for a single connection side.
|
||||||
* @param plugin - the plugin that spawned this listener.
|
* @param plugin - the plugin that spawned this listener.
|
||||||
|
Loading…
Reference in New Issue
Block a user