use of com.bergerkiller.bukkit.common.events.PacketReceiveEvent 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;
}
use of com.bergerkiller.bukkit.common.events.PacketReceiveEvent in project BKCommonLib by bergerhealer.
the class PortalHandler_1_9 method enable.
@Override
public void enable(CommonPlugin plugin) {
// Listener to disable player portal events pre-emptively while players are viewing credits
// This is required, otherwise other plugins get very confused and teleport players out of the
// credits screen.
plugin.register(new Listener() {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onPortalEvent(PlayerPortalEvent event) {
if (EntityPlayerHandle.fromBukkit(event.getPlayer()).isViewingCredits()) {
event.setCancelled(true);
}
}
});
// While the player is inside the end portal, it continuously fires a portal enter event.
// This causes a horrible sound effect to play, because that effect is sent every tick.
// This is obviously very unwanted while viewing the credits!
plugin.register(new PacketListener() {
@Override
public void onPacketReceive(PacketReceiveEvent event) {
}
@Override
public void onPacketSend(PacketSendEvent event) {
if (EntityPlayerHandle.fromBukkit(event.getPlayer()).isViewingCredits()) {
event.setCancelled(true);
}
}
}, PacketType.OUT_WORLD_EVENT);
}
Aggregations