ProtocolLib/src/main/java/com/comphenix/protocol/events/MonitorAdapter.java

78 lines
2.6 KiB
Java
Raw Normal View History

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;
import com.comphenix.protocol.injector.packet.PacketRegistry;
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 {
2023-05-12 16:35:34 +02:00
private final Plugin plugin;
private final ListeningWhitelist sending;
private final ListeningWhitelist receiving;
2012-10-13 22:19:01 +02:00
2023-05-12 16:35:34 +02:00
public MonitorAdapter(Plugin plugin, ConnectionSide side) {
this.plugin = plugin;
2022-08-24 02:53:55 +02:00
2023-05-12 16:35:34 +02:00
// 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;
}
2022-08-24 02:53:55 +02:00
2023-05-12 16:35:34 +02:00
@Deprecated
public MonitorAdapter(Plugin plugin, ConnectionSide side, Logger logger) {
this(plugin, side);
}
2023-05-12 16:35:34 +02:00
private static ListeningWhitelist buildWhitelist(Collection<PacketType> packetTypes) {
return ListeningWhitelist.newBuilder().monitor().gamePhaseBoth().types(packetTypes).build();
}
2023-05-12 16:35:34 +02:00
@Override
public ListeningWhitelist getSendingWhitelist() {
return this.sending;
}
2022-08-24 02:53:55 +02:00
2023-05-12 16:35:34 +02:00
@Override
public ListeningWhitelist getReceivingWhitelist() {
return this.receiving;
}
2022-08-24 02:53:55 +02:00
2023-05-12 16:35:34 +02:00
@Override
public Plugin getPlugin() {
return this.plugin;
}
2022-08-24 02:53:55 +02:00
2023-05-12 16:35:34 +02:00
@Override
public void onPacketSending(PacketEvent event) {
}
2012-10-13 22:19:01 +02:00
2023-05-12 16:35:34 +02:00
@Override
public void onPacketReceiving(PacketEvent event) {
}
2022-08-24 02:53:55 +02:00
}