@SubscribeEvent public void serverPacket( final ServerCustomPacketEvent ev ) { // find player final NetHandlerPlayServer srv = (NetHandlerPlayServer) ev.getPacket().handler(); try { if ( serverPacketHandler != null ) { serverPacketHandler.onPacketData( ev.getPacket(), ev.getHandler(), srv.playerEntity ); } } catch ( final ThreadQuickExitException ext ) { ; } }
/** * Invoked when the server receives a packet from the client */ @SubscribeEvent public void onClientPacket(final ServerCustomPacketEvent event) { if (!event.getPacket().channel().equals(Reference.CHANNEL)) return; ((NetHandlerPlayServer) event.getHandler()).player.getServerWorld().addScheduledTask(new Runnable() { @Override public void run() { try {handleClientPacket(event.getPacket(), ((NetHandlerPlayServer) event.getHandler()).player);} catch (Exception ex) { ex.printStackTrace(); MoreCommands.INSTANCE.getLogger().warn("Error handling Packet"); } } }); }
@SubscribeEvent public void messageFromClient(ServerCustomPacketEvent event) { MinecraftServer.getServer().addScheduledTask(new Runnable() { @Override public void run() { EntityPlayerMP player = ((NetHandlerPlayServer) event.handler).playerEntity; try { handleMessageFromClient(player, event.packet.payload()); } catch (IOException e) { e.printStackTrace(); } } }); }
@SubscribeEvent public void onPacket(final ServerCustomPacketEvent event) { WorldServer world = ((NetHandlerPlayServer) event.handler).playerEntity.getServerForPlayer(); if (!world.isCallingFromMinecraftThread()) { world.addScheduledTask(new Runnable() { public void run() { handlePacket(event, true, ((NetHandlerPlayServer) event.handler).playerEntity); } }); } else { handlePacket(event, true, ((NetHandlerPlayServer) event.handler).playerEntity); } }
@SubscribeEvent public void serverCustomPayload(ServerCustomPacketEvent event) { EntityPlayerMP player = ((NetHandlerPlayServer)event.getHandler()).playerEntity; World handlerWorld = player.world; ServerState.checkIfServerChanged(handlerWorld.getMinecraftServer(), handlerWorld.getWorldInfo()); CustomPacketPayload payload = CustomPacketPayload.decodePacket(event.getPacket()); if (payload != null) { switch (payload.type) { case DebuggingGeometryRequest: GeometryData geometryData = null; if (player.mcServer.getPlayerList().canSendCommands(player.getGameProfile())); { geometryData = ServerState.getDebuggingGeometryData((GeometryRequestData)payload.data); } if (geometryData == null) { (new CustomPacketPayload(PayloadType.DebuggingGeometryRenderMode, "_DISABLE_")).sendToClient(player); } else { (new CustomPacketPayload(PayloadType.DebuggingGeometryData, geometryData)).sendToClient(player); } break; default: throw new RuntimeException("Unhandled server packet type " + payload.type); } } }