2012-12-27 14:28:33 +01:00
|
|
|
/*
|
|
|
|
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
|
|
|
|
* Copyright (C) 2012 Kristian S. Stangeland
|
|
|
|
*
|
2022-08-24 02:53:55 +02:00
|
|
|
* 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
|
2012-12-27 14:28:33 +01:00
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
2022-08-24 02:53:55 +02:00
|
|
|
* 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.
|
2012-12-27 14:28:33 +01:00
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
2022-08-24 02:53:55 +02:00
|
|
|
* 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
|
2012-12-27 14:28:33 +01:00
|
|
|
* 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2012-10-13 22:19:01 +02:00
|
|
|
package com.comphenix.protocol.events;
|
|
|
|
|
2022-08-24 02:53:55 +02:00
|
|
|
import java.util.Collection;
|
2012-10-13 22:19:01 +02:00
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
2022-08-24 02:53:55 +02:00
|
|
|
import com.comphenix.protocol.PacketType;
|
2013-12-05 06:52:20 +01:00
|
|
|
import com.comphenix.protocol.injector.packet.PacketRegistry;
|
2020-06-06 21:13:29 +02:00
|
|
|
import org.bukkit.plugin.Plugin;
|
2012-10-13 22:19:01 +02:00
|
|
|
|
|
|
|
/**
|
2013-12-05 21:24:31 +01:00
|
|
|
* Represents a listener that is notified of every sent and received packet.
|
2022-08-24 02:53:55 +02:00
|
|
|
*
|
2012-10-13 22:19:01 +02:00
|
|
|
* @author Kristian
|
|
|
|
*/
|
|
|
|
public abstract class MonitorAdapter implements PacketListener {
|
|
|
|
|
2022-08-24 02:53:55 +02:00
|
|
|
private final Plugin plugin;
|
|
|
|
private final ListeningWhitelist sending;
|
|
|
|
private final ListeningWhitelist receiving;
|
2012-10-13 22:19:01 +02:00
|
|
|
|
|
|
|
public MonitorAdapter(Plugin plugin, ConnectionSide side) {
|
2022-08-24 02:53:55 +02:00
|
|
|
this.plugin = plugin;
|
|
|
|
|
|
|
|
// check the connection side and register the packets for the given side
|
|
|
|
this.sending = side.isForServer() ? buildWhitelist(PacketRegistry.getServerPacketTypes()) : ListeningWhitelist.EMPTY_WHITELIST;
|
|
|
|
this.receiving = side.isForClient() ? buildWhitelist(PacketRegistry.getClientPacketTypes()) : ListeningWhitelist.EMPTY_WHITELIST;
|
2012-10-13 22:19:01 +02:00
|
|
|
}
|
2022-08-24 02:53:55 +02:00
|
|
|
|
|
|
|
@Deprecated
|
2012-10-13 22:19:01 +02:00
|
|
|
public MonitorAdapter(Plugin plugin, ConnectionSide side, Logger logger) {
|
2022-08-24 02:53:55 +02:00
|
|
|
this(plugin, side);
|
2012-10-16 07:58:30 +02:00
|
|
|
}
|
2020-06-06 21:13:29 +02:00
|
|
|
|
2022-08-24 02:53:55 +02:00
|
|
|
private static ListeningWhitelist buildWhitelist(Collection<PacketType> packetTypes) {
|
|
|
|
return ListeningWhitelist.newBuilder().monitor().gamePhaseBoth().types(packetTypes).build();
|
2012-10-13 22:19:01 +02:00
|
|
|
}
|
2020-06-06 21:13:29 +02:00
|
|
|
|
2012-10-13 22:19:01 +02:00
|
|
|
@Override
|
|
|
|
public ListeningWhitelist getSendingWhitelist() {
|
2022-08-24 02:53:55 +02:00
|
|
|
return this.sending;
|
2012-10-13 22:19:01 +02:00
|
|
|
}
|
2022-08-24 02:53:55 +02:00
|
|
|
|
2012-10-13 22:19:01 +02:00
|
|
|
@Override
|
|
|
|
public ListeningWhitelist getReceivingWhitelist() {
|
2022-08-24 02:53:55 +02:00
|
|
|
return this.receiving;
|
2012-10-13 22:19:01 +02:00
|
|
|
}
|
2022-08-24 02:53:55 +02:00
|
|
|
|
2012-10-13 22:19:01 +02:00
|
|
|
@Override
|
|
|
|
public Plugin getPlugin() {
|
2022-08-24 02:53:55 +02:00
|
|
|
return this.plugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPacketSending(PacketEvent event) {
|
2012-10-13 22:19:01 +02:00
|
|
|
}
|
|
|
|
|
2022-08-24 02:53:55 +02:00
|
|
|
@Override
|
|
|
|
public void onPacketReceiving(PacketEvent event) {
|
|
|
|
}
|
|
|
|
}
|